Skip to content

Instantly share code, notes, and snippets.

@brigand
Created June 21, 2021 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brigand/560b4a9e4a0668bb389ac26a251ca52f to your computer and use it in GitHub Desktop.
Save brigand/560b4a9e4a0668bb389ac26a251ca52f to your computer and use it in GitHub Desktop.
const create = sessionUser => data => Promise.try(() => transaction(model, async (modelTransaction) => {
const { CAN_CREATE_ORGANIZATIONS } = getPermissions(sessionUser.permissions);
const { userId } = sessionUser;
const { avatar, ...orgData } = data;
if (!CAN_CREATE_ORGANIZATIONS) {
throw Unauthorized({ message: 'Sie haben nicht das Recht Organisationen zu erstellen' });
}
const insert = params => modelTransaction.query()
.insert({
...orgData,
...params,
createdBy: userId,
updatedBy: userId,
})
.returning(['id', 'name']);
if (avatar) {
const uuid = await saveAvatar({
path: orgAvatarPath,
file: avatar,
});
return insert({ avatar: uuid });
} else {
return insert({});
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment