-
-
Save brigand/560b4a9e4a0668bb389ac26a251ca52f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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