CognxSafeTrack
Claude Sonnet 4.6
feat(agentic-week2-4): 5 major features — AI content generator, handoff, tags, soft-delete, SSE
99f6bca Download apps/api/src/services/user-admin-service.ts from safetrack/edtech: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/spaces/safetrack/edtech/resolve/main/apps/api/src/services/user-admin-service.ts
- Command line
-
hf download hf://spaces/safetrack/edtech/apps/api/src/services/user-admin-service.ts
-
curl -L -o user-admin-service.ts https://huggingface.co/spaces/safetrack/edtech/resolve/main/apps/api/src/services/user-admin-service.ts
1.99 kB
| import { prisma } from './prisma'; | |
| export class UserAdminService { | |
| static async softDeleteUser(organizationId: string, userId: string): Promise<boolean> { | |
| const result = await prisma.user.updateMany({ | |
| where: { id: userId, organizationId, deletedAt: null }, | |
| data: { deletedAt: new Date() }, | |
| }); | |
| return result.count > 0; | |
| } | |
| static async softDeleteEnrollment(organizationId: string, enrollmentId: string): Promise<boolean> { | |
| const result = await prisma.enrollment.updateMany({ | |
| where: { id: enrollmentId, organizationId, deletedAt: null }, | |
| data: { deletedAt: new Date() }, | |
| }); | |
| return result.count > 0; | |
| } | |
| static async listUsers(organizationId: string, page: number, limit: number) { | |
| const [users, total] = await Promise.all([ | |
| prisma.user.findMany({ | |
| where: { organizationId, deletedAt: null }, | |
| orderBy: { createdAt: 'desc' }, | |
| skip: (page - 1) * limit, | |
| take: limit, | |
| include: { | |
| enrollments: { include: { track: true }, orderBy: { startedAt: 'desc' }, take: 1 }, | |
| _count: { select: { enrollments: true, responses: true } } | |
| } | |
| }), | |
| prisma.user.count({ where: { organizationId, deletedAt: null } }) | |
| ]); | |
| return { users, total, page, limit }; | |
| } | |
| static async getUserMessages(organizationId: string, userId: string) { | |
| const [messages, user] = await Promise.all([ | |
| prisma.message.findMany({ | |
| where: { userId, organizationId }, | |
| orderBy: { createdAt: 'asc' }, | |
| }), | |
| prisma.user.findFirst({ | |
| where: { id: userId, organizationId }, | |
| select: { id: true, name: true, phone: true } | |
| }) | |
| ]); | |
| if (!user) return null; | |
| return { user, messages }; | |
| } | |
| } | |