mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-22 23:52:30 +02:00
feat: add validation for teams and organization
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user