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
|
email String @unique
|
||||||
name String?
|
name String?
|
||||||
posts Post[]
|
posts Post[]
|
||||||
createdAt DateTime
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model Post {
|
model Post {
|
||||||
|
|
@ -30,6 +30,6 @@ model Post {
|
||||||
published Boolean @default(false)
|
published Boolean @default(false)
|
||||||
author User @relation(fields: [authorId], references: [id])
|
author User @relation(fields: [authorId], references: [id])
|
||||||
authorId Int
|
authorId Int
|
||||||
createdAt DateTime
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
}
|
}
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import { builder } from '../builder';
|
import { builder } from '../builder';
|
||||||
|
|
||||||
export const Date = builder.scalarType('Date', {
|
export const DateScalar = builder.scalarType('Date', {
|
||||||
description: 'Date Scalar in ISO format',
|
description: 'Date Scalar in ISO format',
|
||||||
serialize: (t) => {
|
serialize: (date) => {
|
||||||
return t.toISOString();
|
return date.toISOString();
|
||||||
},
|
},
|
||||||
parseValue: (date) => {
|
parseValue: (date) => {
|
||||||
if (typeof date !== 'string') {
|
if (typeof date !== 'string') {
|
||||||
throw new Error('Cyka blyat');
|
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 * from './Date';
|
||||||
|
|
||||||
export type Scalars = {
|
export type Scalars = {
|
||||||
Date: {
|
Date: {
|
||||||
Input: Dayjs;
|
Input: Date;
|
||||||
Output: Dayjs;
|
Output: Date;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -6,7 +6,13 @@ const User = builder.prismaObject('User', {
|
||||||
id: t.exposeID('id'),
|
id: t.exposeID('id'),
|
||||||
email: t.exposeString('email'),
|
email: t.exposeString('email'),
|
||||||
name: t.exposeString('name'),
|
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'),
|
title: t.exposeString('title'),
|
||||||
content: t.exposeString('content'),
|
content: t.exposeString('content'),
|
||||||
published: t.exposeBoolean('published'),
|
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