Download apps/backend/src/api/routes/admin.controller.ts from Leon4gr45/postio: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/spaces/Leon4gr45/postio/resolve/main/apps/backend/src/api/routes/admin.controller.ts
- Command line
-
hf download hf://spaces/Leon4gr45/postio/apps/backend/src/api/routes/admin.controller.ts
-
curl -L -o admin.controller.ts https://huggingface.co/spaces/Leon4gr45/postio/resolve/main/apps/backend/src/api/routes/admin.controller.ts
2.13 kB
| import { | |
| Controller, | |
| Get, | |
| HttpException, | |
| Query, | |
| } from '@nestjs/common'; | |
| import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request'; | |
| import { User } from '@prisma/client'; | |
| import { ApiTags } from '@nestjs/swagger'; | |
| import { ErrorsService } from '@gitroom/nestjs-libraries/database/prisma/errors/errors.service'; | |
| import { AdminStatsService } from '@gitroom/nestjs-libraries/database/prisma/admin-stats/admin-stats.service'; | |
| import dayjs from 'dayjs'; | |
| ('Admin') | |
| ('/admin') | |
| export class AdminController { | |
| constructor( | |
| private _errorsService: ErrorsService, | |
| private _adminStatsService: AdminStatsService | |
| ) {} | |
| private assertSuperAdmin(user: User) { | |
| if (!user?.isSuperAdmin) { | |
| throw new HttpException('Unauthorized', 400); | |
| } | |
| } | |
| ('/errors') | |
| async listErrors( | |
| () user: User, | |
| ('page') page?: string, | |
| ('limit') limit?: string, | |
| ('platform') platform?: string, | |
| ('email') email?: string, | |
| ('unknownFirst') unknownFirst?: string | |
| ) { | |
| this.assertSuperAdmin(user); | |
| return this._errorsService.listErrors({ | |
| page: page ? parseInt(page, 10) : 0, | |
| limit: limit ? parseInt(limit, 10) : 20, | |
| platform: platform || undefined, | |
| email: email || undefined, | |
| unknownFirst: unknownFirst === 'true' || unknownFirst === '1', | |
| }); | |
| } | |
| ('/errors/platforms') | |
| async listPlatforms(() user: User) { | |
| this.assertSuperAdmin(user); | |
| return this._errorsService.listPlatforms(); | |
| } | |
| ('/stats') | |
| async getStats( | |
| () user: User, | |
| ('from') from?: string, | |
| ('to') to?: string, | |
| ('unknownOnly') unknownOnly?: string | |
| ) { | |
| this.assertSuperAdmin(user); | |
| const fromDate = from ? dayjs(from) : dayjs().subtract(30, 'day'); | |
| const toDate = to ? dayjs(to) : dayjs(); | |
| return this._adminStatsService.getStats({ | |
| from: fromDate.startOf('day').toDate(), | |
| to: toDate.endOf('day').toDate(), | |
| unknownOnly: unknownOnly === 'true' || unknownOnly === '1', | |
| }); | |
| } | |
| } | |