-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgetTime.ts
64 lines (58 loc) · 1.38 KB
/
getTime.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { autoService } from 'knifecycle';
import {
refersTo,
type WhookAPISchemaDefinition,
type WhookAPIHandlerDefinition,
type WhookAPITypedHandler,
} from '@whook/whook';
import { type TimeService } from 'common-services';
export const timeSchema = {
name: 'TimeSchema',
schema: {
type: 'object',
additionalProperties: false,
properties: {
currentDate: {
type: 'string',
format: 'date-time',
},
},
},
} as const satisfies WhookAPISchemaDefinition<
components['schemas']['TimeSchema']
>;
/* Architecture Note #3.4.3: getTime
Returns the server time.
*/
export const definition = {
path: '/time',
method: 'get',
operation: {
operationId: 'getTime',
summary: 'Get API internal clock date.',
tags: ['system'],
responses: {
200: {
description: 'Server current date',
content: {
'application/json': {
schema: refersTo(timeSchema),
},
},
},
},
},
} as const satisfies WhookAPIHandlerDefinition;
async function initGetTime({ time }: { time: TimeService }) {
const handler: WhookAPITypedHandler<
operations[typeof definition.operation.operationId],
typeof definition
> = async () => ({
status: 200,
body: {
currentDate: new Date(time()).toISOString(),
},
});
return handler;
}
export default autoService(initGetTime);