-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase-entry.ts
More file actions
51 lines (47 loc) · 935 Bytes
/
database-entry.ts
File metadata and controls
51 lines (47 loc) · 935 Bytes
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
interface DatabaseOptions {
id?: 'uuid' | 'number' | 'string';
softDeletion?: boolean;
}
/**
* Inserts common database fields into a model
*
* @param {string} params.id One of 'uuid', 'number', or 'string' for the "type" key
* @param {boolean} params.softDeletion If true, adds "deletedAt" date
*
* @return {string}
*/
const databaseEntry = (params?: DatabaseOptions): string => {
params = params || {};
if (!params?.id) {
params.id = 'uuid';
}
const idType = params.id === 'number' ? 'number' : 'string';
return `
id:
type: ${idType}\
${
params.id === 'uuid'
? `
format: uuid
`
: ''
}
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time\
${
params?.softDeletion
? `
deletedAt:
type: string
format: date-time
nullable: true
`
: ''
}
`;
};
module.exports = databaseEntry;