This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
know-it-all/server/routes/org/CreateOrg.js
2022-03-30 09:46:43 -05:00

25 lines
598 B
JavaScript

async function CreateOrg(req, res, next) {
const user = req.user;
const orgName = req.body.orgName;
if (!orgName) {
return res.status(400).send('Form missing necessary fields');
}
const existing = await user.countOwnedOrg({
where: { orgName: orgName },
});
if (existing > 0) {
return res
.status(500)
.send('This user already has an organization with this name.');
}
const org = await user.createOwnedOrg({
orgName: orgName,
});
return res.status(200).send(org);
}
module.exports = CreateOrg;