Skip to content

Commit

Permalink
Merge pull request #102 from ngyngcphu/fix/stat-uploaded-model-api
Browse files Browse the repository at this point in the history
fix: uploaded model api now consider default models only
  • Loading branch information
HuyDNA authored Dec 31, 2023
2 parents cb3b2d3 + dc6f818 commit 9b02c98
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/dtos/in/stat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const JoinedUserStatQuerystringDto = Type.Object({
interval: Type.Number({ minimum: 1, multipleOf: 1, default: 1, description: 'The length of a sub-interval' })
});

export const UploadedUserModelStatQuerystringDto = Type.Object({
export const UploadedModelStatQuerystringDto = Type.Object({
start: Type.String({ format: 'date', description: 'The start date of the interval' }),
end: Type.String({ format: 'date', description: 'The end date of the interval' }),
unit: Type.Union([Type.Literal('day'), Type.Literal('month')], {
Expand All @@ -37,6 +37,6 @@ export const RevenueStatQuerystringDto = Type.Object({

export type RevenueStatQuerystringDto = Static<typeof RevenueStatQuerystringDto>;

export type UploadedUserModelStatQuerystringDto = Static<typeof UploadedUserModelStatQuerystringDto>;
export type UploadedModelStatQuerystringDto = Static<typeof UploadedModelStatQuerystringDto>;

export type JoinedUserStatQuerystringDto = Static<typeof JoinedUserStatQuerystringDto>;
4 changes: 2 additions & 2 deletions src/dtos/out/stat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const JoinedUserStatResultDto = Type.Array(
})
);

export const UploadedUserModelStatResultDto = Type.Array(
export const UploadedModelStatResultDto = Type.Array(
Type.Object({
start: Type.String({ format: 'date' }),
end: Type.String({ format: 'date' }),
Expand All @@ -37,7 +37,7 @@ export const RevenueStatResultDto = Type.Array(

export type RevenueStatResultDto = Static<typeof RevenueStatResultDto>;

export type UploadedUserModelStatResultDto = Static<typeof UploadedUserModelStatResultDto>;
export type UploadedModelStatResultDto = Static<typeof UploadedModelStatResultDto>;

export type JoinedUserStatResultDto = Static<typeof JoinedUserStatResultDto>;

Expand Down
10 changes: 4 additions & 6 deletions src/handlers/stat.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CategoryStatResultDto, JoinedUserStatResultDto, RevenueStatResultDto, UploadedUserModelStatResultDto } from '@dtos/out';
import { CategoryStatResultDto, JoinedUserStatResultDto, RevenueStatResultDto, UploadedModelStatResultDto } from '@dtos/out';
import { Handler } from '@interfaces';
import { prisma } from '@repositories';
import { JoinedUserStatQuerystringDto, RevenueStatQuerystringDto, UploadedUserModelStatQuerystringDto } from 'src/dtos/in/stat.dto';
import { JoinedUserStatQuerystringDto, RevenueStatQuerystringDto, UploadedModelStatQuerystringDto } from 'src/dtos/in/stat.dto';

const noByCategory: Handler<CategoryStatResultDto> = async () => {
const cats = await prisma.defaultModel.groupBy({
Expand Down Expand Up @@ -79,14 +79,12 @@ const joinedUsers: Handler<JoinedUserStatResultDto, { Querystring: JoinedUserSta
}));
};

const uploadedUserModelCount: Handler<UploadedUserModelStatResultDto, { Querystring: UploadedUserModelStatQuerystringDto }> = async (
req
) => {
const uploadedUserModelCount: Handler<UploadedModelStatResultDto, { Querystring: UploadedModelStatQuerystringDto }> = async (req) => {
const { start: _start, end: _end, interval, unit } = req.query;
const start = new Date(_start);
const end = new Date(_end);

const newModels = await prisma.uploadedModel.findMany({
const newModels = await prisma.defaultModel.findMany({
select: {
model: {
select: {
Expand Down
10 changes: 5 additions & 5 deletions src/routes/apis/stat.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JoinedUserStatQuerystringDto, RevenueStatQuerystringDto, UploadedUserModelStatQuerystringDto } from '@dtos/in';
import { CategoryStatResultDto, JoinedUserStatResultDto, RevenueStatResultDto, UploadedUserModelStatResultDto } from '@dtos/out';
import { JoinedUserStatQuerystringDto, RevenueStatQuerystringDto, UploadedModelStatQuerystringDto } from '@dtos/in';
import { CategoryStatResultDto, JoinedUserStatResultDto, RevenueStatResultDto, UploadedModelStatResultDto } from '@dtos/out';
import { statHandler } from '@handlers';
import { verifyToken, verifyUserRole } from '@hooks';
import { UserRole } from '@prisma/client';
Expand Down Expand Up @@ -49,10 +49,10 @@ export const statPlugin = createRoutes('Stat', [
url: '/userModel',
onRequest: [verifyToken, verifyUserRole(UserRole.MANAGER)],
schema: {
summary: 'Summarize the total uploaded user models in a given interval',
querystring: UploadedUserModelStatQuerystringDto,
summary: 'Summarize the total uploaded default models in a given interval',
querystring: UploadedModelStatQuerystringDto,
response: {
200: UploadedUserModelStatResultDto
200: UploadedModelStatResultDto
}
},
handler: statHandler.uploadedUserModelCount
Expand Down

0 comments on commit 9b02c98

Please sign in to comment.