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

27 lines
716 B
JavaScript

async function CreateOrg(req, res, next) {
const user = req.user;
const orgName = req.body.orgName;
// Error if the form does not contain an organization name
if (!orgName) {
return res.status(400).send('Form missing necessary fields');
}
// Verify that no owned organizations have the same name
const existing = await user.countOwnedOrg({
where: { name: orgName },
});
if (existing > 0) {
return res
.status(500)
.send('This user already has an organization with this name.');
}
const org = await user.createOwnedOrg({
name: orgName,
});
return res.status(200).send(org);
}
module.exports = CreateOrg;