feat: add validation for teams and organization

This commit is contained in:
prafull-opensignlabs
2024-07-23 19:43:36 +05:30
parent 65ce0d430c
commit 69d4254b44
14 changed files with 422 additions and 120 deletions
@@ -0,0 +1,33 @@
export default async function updateOrganization(request) {
const orgId = request.params.orgId;
const isactive = request.params.isactive;
if (!request?.user) {
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
}
try {
const orgQuery = new Parse.Query('contracts_Organizations');
orgQuery.equalTo('objectId', orgId);
orgQuery.equalTo('CreatedBy', {
__type: 'Pointer',
className: '_User',
objectId: request.user.id,
});
const resOrg = await orgQuery.first({ useMasterKey: true });
if (resOrg) {
const newOrg = new Parse.Object('contracts_Organizations');
newOrg.id = orgId;
newOrg.set('IsActive', isactive);
const newResOrg = await newOrg.save(null, { useMasterKey: true });
if (newResOrg) {
return newResOrg;
}
} else {
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'Premission denied.');
}
} catch (err) {
console.log('err in addorganization', err);
const code = err?.code || 400;
const msg = err?.message || 'Something went wrong.';
throw new Parse.Error(code, msg);
}
}