mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign). Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files) and align docker/Dockerfile turbo --scope/--filter to the actual remix package name @hanzo/esign (was a pre-existing mismatch with -remix that broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
73 lines
1.6 KiB
TypeScript
73 lines
1.6 KiB
TypeScript
import { EnvelopeType } from '@prisma/client';
|
|
|
|
import { prisma } from '@hanzo/esign-prisma';
|
|
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
import { mapSecondaryIdToDocumentId, mapSecondaryIdToTemplateId } from '../../utils/envelope';
|
|
import { buildTeamWhereQuery } from '../../utils/teams';
|
|
|
|
export type GetRecipientByIdOptions = {
|
|
recipientId: number;
|
|
userId: number;
|
|
teamId: number;
|
|
type: EnvelopeType;
|
|
};
|
|
|
|
/**
|
|
* Get a recipient by ID. This will also return the recipient signing token so
|
|
* be careful when using this.
|
|
*/
|
|
export const getRecipientById = async ({
|
|
recipientId,
|
|
userId,
|
|
teamId,
|
|
type,
|
|
}: GetRecipientByIdOptions) => {
|
|
const recipient = await prisma.recipient.findFirst({
|
|
where: {
|
|
id: recipientId,
|
|
envelope: {
|
|
type,
|
|
team: buildTeamWhereQuery({ teamId, userId }),
|
|
},
|
|
},
|
|
include: {
|
|
fields: true,
|
|
envelope: {
|
|
select: {
|
|
secondaryId: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!recipient) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'Recipient not found',
|
|
});
|
|
}
|
|
|
|
const legacyId = {
|
|
documentId:
|
|
type === EnvelopeType.DOCUMENT
|
|
? mapSecondaryIdToDocumentId(recipient.envelope.secondaryId)
|
|
: null,
|
|
templateId:
|
|
type === EnvelopeType.TEMPLATE
|
|
? mapSecondaryIdToTemplateId(recipient.envelope.secondaryId)
|
|
: null,
|
|
};
|
|
|
|
// Backwards compatibility mapping.
|
|
return {
|
|
...recipient,
|
|
...legacyId,
|
|
|
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
fields: recipient.fields.map((field) => ({
|
|
...field,
|
|
...legacyId,
|
|
})),
|
|
};
|
|
};
|