mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
94 lines
2.2 KiB
TypeScript
94 lines
2.2 KiB
TypeScript
import type { Envelope, TemplateDirectLink } from '@prisma/client';
|
|
import { EnvelopeType, type TeamProfile, TemplateType } from '@prisma/client';
|
|
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
|
|
export type GetPublicProfileByUrlOptions = {
|
|
profileUrl: string;
|
|
};
|
|
|
|
type PublicDirectLinkTemplate = Pick<Envelope, 'id' | 'publicTitle' | 'publicDescription'> & {
|
|
directLink: TemplateDirectLink;
|
|
};
|
|
|
|
type GetPublicProfileByUrlResponse = {
|
|
url: string;
|
|
name: string;
|
|
avatarImageId?: string | null;
|
|
badge?: {
|
|
type: 'Premium' | 'EarlySupporter';
|
|
since: Date;
|
|
};
|
|
templates: PublicDirectLinkTemplate[];
|
|
profile: TeamProfile;
|
|
};
|
|
|
|
/**
|
|
* Get the user or team public profile by URL.
|
|
*/
|
|
export const getPublicProfileByUrl = async ({
|
|
profileUrl,
|
|
}: GetPublicProfileByUrlOptions): Promise<GetPublicProfileByUrlResponse> => {
|
|
const team = await prisma.team.findFirst({
|
|
where: {
|
|
url: profileUrl,
|
|
profile: {
|
|
enabled: true,
|
|
},
|
|
},
|
|
include: {
|
|
profile: true,
|
|
envelopes: {
|
|
where: {
|
|
type: EnvelopeType.TEMPLATE,
|
|
templateType: TemplateType.PUBLIC,
|
|
directLink: {
|
|
enabled: true,
|
|
},
|
|
},
|
|
include: {
|
|
directLink: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!team?.profile?.enabled) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'Profile not found',
|
|
});
|
|
}
|
|
|
|
return {
|
|
badge: {
|
|
type: 'Premium',
|
|
since: team.createdAt,
|
|
},
|
|
profile: {
|
|
teamId: team.profile.teamId,
|
|
id: team.profile.id,
|
|
enabled: team.profile.enabled,
|
|
bio: team.profile.bio,
|
|
},
|
|
url: profileUrl,
|
|
avatarImageId: team.avatarImageId,
|
|
name: team.name || '',
|
|
templates: team.envelopes.map((template) => {
|
|
const directLink = template.directLink;
|
|
|
|
if (!directLink || !directLink.enabled || template.templateType !== TemplateType.PUBLIC) {
|
|
throw new Error('Not possible');
|
|
}
|
|
|
|
return {
|
|
id: template.id,
|
|
publicTitle: template.publicTitle,
|
|
publicDescription: template.publicDescription,
|
|
directLink,
|
|
};
|
|
}),
|
|
};
|
|
};
|