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

25 lines
587 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 = user.getOwnedOrg();
if (existing) {
return res
.status(500)
.send(
'This user already owns an organization, delete it to create another.'
);
}
const org = await user.createOwnedOrg({
orgName: orgName,
});
return res.status(200).send(org);
}
module.exports = CreateOrg;