got timestamps working
This commit is contained in:
parent
084faf12f9
commit
77142e4df5
4 changed files with 24 additions and 15 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
export * from './Date';
|
||||
|
||||
export type Scalars = {
|
||||
Date: {
|
||||
Input: Dayjs;
|
||||
Output: Dayjs;
|
||||
Input: Date;
|
||||
Output: Date;
|
||||
};
|
||||
};
|
||||
|
|
@ -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'
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue