mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-20 22:52:39 +02:00
fix: incompatible pdf issue and signturetype issues
This commit is contained in:
@@ -1,29 +1,48 @@
|
||||
import { parseJwt } from '../../Utils.js';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
async function getTenantByUserId(userId) {
|
||||
async function getTenantByUserId(userId, contactId) {
|
||||
try {
|
||||
const query = new Parse.Query('contracts_Users');
|
||||
query.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: userId,
|
||||
});
|
||||
const extuser = await query.first({ useMasterKey: true });
|
||||
if (extuser) {
|
||||
const user = extuser?.get('CreatedBy')?.id || userId;
|
||||
const tenantCreditsQuery = new Parse.Query('partners_Tenant');
|
||||
tenantCreditsQuery.equalTo('UserId', {
|
||||
if (contactId) {
|
||||
const contactquery = new Parse.Query('contracts_Contactbook');
|
||||
contactquery.equalTo('objectId', contactId);
|
||||
const contactuser = await contactquery.first({ useMasterKey: true });
|
||||
if (contactuser) {
|
||||
const user = contactuser?.get('CreatedBy')?.id || userId;
|
||||
const tenantCreditsQuery = new Parse.Query('partners_Tenant');
|
||||
tenantCreditsQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: user,
|
||||
});
|
||||
tenantCreditsQuery.exclude('FileAdapters,PfxFile,ContactNumber');
|
||||
const res = await tenantCreditsQuery.first({ useMasterKey: true });
|
||||
return res;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
const query = new Parse.Query('contracts_Users');
|
||||
query.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: user,
|
||||
objectId: userId,
|
||||
});
|
||||
tenantCreditsQuery.exclude('FileAdapters');
|
||||
tenantCreditsQuery.exclude('PfxFile');
|
||||
const res = await tenantCreditsQuery.first({ useMasterKey: true });
|
||||
return res;
|
||||
} else {
|
||||
return {};
|
||||
const extuser = await query.first({ useMasterKey: true });
|
||||
if (extuser) {
|
||||
const user = extuser?.get('CreatedBy')?.id || userId;
|
||||
const tenantCreditsQuery = new Parse.Query('partners_Tenant');
|
||||
tenantCreditsQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: user,
|
||||
});
|
||||
tenantCreditsQuery.exclude('FileAdapters,PfxFile');
|
||||
const res = await tenantCreditsQuery.first({ useMasterKey: true });
|
||||
return res;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in getTenant ', err);
|
||||
@@ -33,6 +52,7 @@ async function getTenantByUserId(userId) {
|
||||
export default async function getTenant(request) {
|
||||
const jwttoken = request.headers.jwttoken || '';
|
||||
const userId = request.params.userId || '';
|
||||
const contactId = request.params.contactId || '';
|
||||
if (jwttoken) {
|
||||
const jwtDecode = parseJwt(jwttoken);
|
||||
if (jwtDecode?.user_email) {
|
||||
@@ -50,12 +70,14 @@ export default async function getTenant(request) {
|
||||
const appRes = await tokenQuery.first({ useMasterKey: true });
|
||||
const decoded = jwt.verify(verifyToken, appRes?.get('token'));
|
||||
if (decoded?.user_email) {
|
||||
return await getTenantByUserId(apiUserId);
|
||||
return await getTenantByUserId(apiUserId, contactId);
|
||||
} else {
|
||||
return { status: 'error', result: 'Invalid token!' };
|
||||
}
|
||||
}
|
||||
} else if (userId) {
|
||||
return await getTenantByUserId(userId);
|
||||
} else if (userId || contactId) {
|
||||
return await getTenantByUserId(userId, contactId);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user