mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
export default async function updateTenant(request) {
|
|
const { tenantId, details } = request.params;
|
|
|
|
if (!tenantId || !details) {
|
|
throw new Parse.Error(400, 'Missing tenantId or details.');
|
|
}
|
|
|
|
if (!request.user) {
|
|
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'unauthorized');
|
|
}
|
|
const validKeys = ['CompletionBody', 'CompletionSubject', 'RequestBody', 'RequestSubject'];
|
|
try {
|
|
const tenant = new Parse.Object('partners_Tenant');
|
|
tenant.id = tenantId;
|
|
// Update tenant details
|
|
Object.keys(details).forEach(key => {
|
|
if (validKeys.includes(key)) {
|
|
if (details?.[key] !== undefined) {
|
|
tenant.set(key, details?.[key]);
|
|
} else {
|
|
tenant.unset(key);
|
|
}
|
|
}
|
|
});
|
|
if (details?.EmailEditorType) tenant.set('EmailEditorType', details.EmailEditorType);
|
|
|
|
const tenantRes = await tenant.save(null, { useMasterKey: true });
|
|
if (tenantRes) {
|
|
const res = JSON.parse(JSON.stringify(tenantRes));
|
|
return res;
|
|
}
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|