0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

Merge pull request #83 from logto-io/gao-log-40

refactor: unify timestamp usage
This commit is contained in:
Gao Sun 2021-08-18 16:46:05 +08:00 committed by GitHub
commit f1052e8f0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 10 deletions

View file

@ -38,7 +38,7 @@ export default function postgresAdapter(modelName: string): ReturnType<AdapterFa
modelName,
id,
payload,
expiresAt: dayjs().add(expiresIn, 'second').unix(),
expiresAt: dayjs().add(expiresIn, 'second').valueOf(),
}),
find: async (id) => findPayloadById(modelName, id),
findByUserCode: async (userCode) => findPayloadByPayloadField(modelName, 'userCode', userCode),

View file

@ -64,7 +64,7 @@ export const findPayloadByPayloadField = async <
export const consumeInstanceById = async (modelName: string, id: string) => {
await pool.query(sql`
update ${table}
set ${fields.consumedAt}=${dayjs().unix()}
set ${fields.consumedAt}=${dayjs().valueOf()}
where ${fields.modelName}=${modelName}
and ${fields.id}=${id}
`);

View file

@ -82,7 +82,7 @@ const getRawType = (value: string): string => {
// eslint-disable-next-line complexity
export const getType = (
value: string
): 'string' | 'number' | 'boolean' | 'Record<string, unknown>' | 'Date' | undefined => {
): 'string' | 'number' | 'boolean' | 'Record<string, unknown>' | undefined => {
switch (getRawType(value)) {
case 'bpchar':
case 'char':
@ -106,16 +106,15 @@ export const getType = (
case 'numeric':
case 'money':
case 'oid':
case 'date':
case 'timestamp':
case 'timestamptz':
return 'number';
case 'bool':
return 'boolean';
case 'json':
case 'jsonb':
return 'Record<string, unknown>';
case 'date':
case 'timestamp':
case 'timestamptz':
return 'Date';
default:
}
};

View file

@ -5,6 +5,6 @@ create table applications (
name varchar(256) not null,
type application_type not null,
oidc_client_metadata jsonb /* @use OidcClientMetadata */ not null,
created_at bigint not null default(extract(epoch from now())),
created_at timestamptz not null default(now()),
primary key (id)
);

View file

@ -2,8 +2,8 @@ create table oidc_model_instances (
model_name varchar(64) not null,
id varchar(128) not null,
payload jsonb /* @use OidcModelInstancePayload */ not null,
expires_at bigint not null,
consumed_at bigint,
expires_at timestamptz not null,
consumed_at timestamptz,
primary key (model_name, id)
);