mirror of
https://github.com/documenso/documenso.git
synced 2026-07-26 18:04:55 +10:00
feat: demo
This commit is contained in:
@@ -3,8 +3,11 @@ import { prisma } from '@documenso/prisma';
|
||||
import type { DocumentAuditLog } from '@documenso/prisma/client';
|
||||
import type { Prisma } from '@documenso/prisma/client';
|
||||
|
||||
import { AppError } from '../../errors/app-error';
|
||||
import type { TDocumentAuditLog } from '../../types/document-audit-logs';
|
||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
|
||||
import { parseDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||
import { buildServerLogger } from '../../utils/logger';
|
||||
|
||||
export interface FindDocumentAuditLogsOptions {
|
||||
userId: number;
|
||||
@@ -97,7 +100,26 @@ export const findDocumentAuditLogs = async ({
|
||||
|
||||
let nextCursor: string | undefined = undefined;
|
||||
|
||||
const parsedData = data.map((auditLog) => parseDocumentAuditLogData(auditLog));
|
||||
let parsedData: TDocumentAuditLog[] = [];
|
||||
|
||||
try {
|
||||
parsedData = data.map((auditLog) => parseDocumentAuditLogData(auditLog));
|
||||
} catch (err) {
|
||||
const error = AppError.parseError(err);
|
||||
|
||||
if (error.code === 'MIGRATION_REQUIRED') {
|
||||
const logger = buildServerLogger();
|
||||
|
||||
logger.error('findDocumentAuditLogs', {
|
||||
level: 'ALERT',
|
||||
error,
|
||||
});
|
||||
|
||||
void logger.flush();
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (parsedData.length > perPage) {
|
||||
const nextItem = parsedData.pop();
|
||||
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
} from '@documenso/prisma/client';
|
||||
|
||||
import { RECIPIENT_ROLES_DESCRIPTION } from '../constants/recipient-roles';
|
||||
import { AppError } from '../errors/app-error';
|
||||
import type {
|
||||
TDocumentAuditLog,
|
||||
TDocumentAuditLogDocumentMetaDiffSchema,
|
||||
@@ -69,7 +70,7 @@ export const parseDocumentAuditLogData = (auditLog: DocumentAuditLog): TDocument
|
||||
// Handle any required migrations here.
|
||||
if (!data.success) {
|
||||
console.error(data.error);
|
||||
throw new Error('Migration required');
|
||||
throw new AppError('MIGRATION_REQUIRED');
|
||||
}
|
||||
|
||||
return data.data;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { LoggerConfig } from 'next-axiom';
|
||||
import { Logger } from 'next-axiom';
|
||||
|
||||
/**
|
||||
* For usage in server-side code.
|
||||
*
|
||||
* When used in a server component, you must flush the logs.
|
||||
*
|
||||
* https://github.com/axiomhq/next-axiom?tab=readme-ov-file#server-components
|
||||
*/
|
||||
export const buildServerLogger = (config?: LoggerConfig) => {
|
||||
return new Logger({
|
||||
source: 'server',
|
||||
...config,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user