Initial SuperAdmin API (NestJS + Prisma)

This commit is contained in:
SuperAdmin
2026-07-23 10:25:32 +03:30
commit 7fbc47766c
43 changed files with 12902 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../prisma/prisma.service';
type AuditInput = {
action: string;
entityType: string;
entityId?: string;
tenantId?: string;
userId?: string;
before?: Prisma.InputJsonValue;
after?: Prisma.InputJsonValue;
meta?: Prisma.InputJsonValue;
};
@Injectable()
export class AuditService {
constructor(private readonly prisma: PrismaService) {}
log(input: AuditInput) {
return this.prisma.auditLog.create({
data: {
action: input.action,
entityType: input.entityType,
entityId: input.entityId,
tenantId: input.tenantId,
userId: input.userId,
before: input.before,
after: input.after,
meta: input.meta,
},
});
}
findAll(limit = 50) {
return this.prisma.auditLog.findMany({
take: Math.min(limit, 200),
orderBy: { createdAt: 'desc' },
include: {
user: { select: { id: true, name: true, email: true } },
tenant: { select: { id: true, slug: true, nameFa: true } },
},
});
}
async findOne(id: string) {
const row = await this.prisma.auditLog.findUnique({
where: { id },
include: {
user: { select: { id: true, name: true, email: true } },
tenant: { select: { id: true, slug: true, nameFa: true } },
},
});
if (!row) {
throw new NotFoundException('لاگ یافت نشد');
}
return row;
}
}