move sdk packages to its own folder and rename api & dashboard
This commit is contained in:
54
apps/dashboard/src/server/api/routers/reference.ts
Normal file
54
apps/dashboard/src/server/api/routers/reference.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { db, getReferences } from '@mixan/db';
|
||||
import { zCreateReference, zRange } from '@mixan/validation';
|
||||
|
||||
import { getChartStartEndDate } from './chart.helpers';
|
||||
|
||||
export const referenceRouter = createTRPCRouter({
|
||||
create: protectedProcedure
|
||||
.input(zCreateReference)
|
||||
.mutation(
|
||||
async ({ input: { title, description, datetime, projectId } }) => {
|
||||
return db.reference.create({
|
||||
data: {
|
||||
title,
|
||||
description,
|
||||
project_id: projectId,
|
||||
date: new Date(datetime),
|
||||
},
|
||||
});
|
||||
}
|
||||
),
|
||||
delete: protectedProcedure
|
||||
.input(z.object({ id: z.string() }))
|
||||
.mutation(async ({ input: { id } }) => {
|
||||
return db.reference.delete({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}),
|
||||
getChartReferences: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
projectId: z.string(),
|
||||
startDate: z.string().nullish(),
|
||||
endDate: z.string().nullish(),
|
||||
range: zRange,
|
||||
})
|
||||
)
|
||||
.query(({ input: { projectId, ...input } }) => {
|
||||
const { startDate, endDate } = getChartStartEndDate(input);
|
||||
return getReferences({
|
||||
where: {
|
||||
project_id: projectId,
|
||||
date: {
|
||||
gte: new Date(startDate),
|
||||
lte: new Date(endDate),
|
||||
},
|
||||
},
|
||||
});
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user