diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6449cf2..8160664 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -19,8 +19,8 @@ model User { email String @unique name String? posts Post[] - createdAt DateTime - updatedAt DateTime + createdAt DateTime @default(now()) + updatedAt DateTime @default(now()) @updatedAt } model Post { @@ -30,6 +30,6 @@ model Post { published Boolean @default(false) author User @relation(fields: [authorId], references: [id]) authorId Int - createdAt DateTime - updatedAt DateTime + createdAt DateTime @default(now()) + updatedAt DateTime @default(now()) @updatedAt } \ No newline at end of file diff --git a/src/lib/server/pothos/Scalars/Date.ts b/src/lib/server/pothos/Scalars/Date.ts index 298596f..6d61571 100644 --- a/src/lib/server/pothos/Scalars/Date.ts +++ b/src/lib/server/pothos/Scalars/Date.ts @@ -1,15 +1,14 @@ -import dayjs from 'dayjs'; import { builder } from '../builder'; -export const Date = builder.scalarType('Date', { +export const DateScalar = builder.scalarType('Date', { description: 'Date Scalar in ISO format', - serialize: (t) => { - return t.toISOString(); + serialize: (date) => { + return date.toISOString(); }, parseValue: (date) => { if (typeof date !== 'string') { throw new Error('Cyka blyat'); } - return dayjs(date); + return new Date(date); } }); \ No newline at end of file diff --git a/src/lib/server/pothos/Scalars/index.ts b/src/lib/server/pothos/Scalars/index.ts index 521b166..0751f41 100644 --- a/src/lib/server/pothos/Scalars/index.ts +++ b/src/lib/server/pothos/Scalars/index.ts @@ -1,10 +1,8 @@ -import type { Dayjs } from 'dayjs'; - export * from './Date'; export type Scalars = { Date: { - Input: Dayjs; - Output: Dayjs; + Input: Date; + Output: Date; }; }; \ No newline at end of file diff --git a/src/lib/server/pothos/schema.ts b/src/lib/server/pothos/schema.ts index 2b06918..0789677 100644 --- a/src/lib/server/pothos/schema.ts +++ b/src/lib/server/pothos/schema.ts @@ -6,7 +6,13 @@ const User = builder.prismaObject('User', { id: t.exposeID('id'), email: t.exposeString('email'), name: t.exposeString('name'), - posts: t.relation('posts') + posts: t.relation('posts'), + createdAt: t.expose('createdAt', { + type: 'Date' + }), + updatedAt: t.expose('updatedAt', { + type: 'Date' + }) }) }); @@ -16,7 +22,13 @@ const Post = builder.prismaObject('Post', { title: t.exposeString('title'), content: t.exposeString('content'), published: t.exposeBoolean('published'), - author: t.relation('author') + author: t.relation('author'), + createdAt: t.expose('createdAt', { + type: 'Date' + }), + updatedAt: t.expose('updatedAt', { + type: 'Date' + }) }) });