express-generator-typescript 2.7.7 → 2.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-git +2 -3
- package/README.md +1 -1
- package/lib/express-generator-typescript.js +1 -1
- package/package.json +1 -1
- package/lib/project-files/README.md +0 -65
- package/lib/project-files/config/.env.development +0 -15
- package/lib/project-files/config/.env.production +0 -15
- package/lib/project-files/config/.env.test +0 -14
- package/lib/project-files/config.ts +0 -22
- package/lib/project-files/eslint.config.ts +0 -100
- package/lib/project-files/gitignore +0 -6
- package/lib/project-files/package.json +0 -57
- package/lib/project-files/scripts/build.ts +0 -28
- package/lib/project-files/scripts/common/utils.ts +0 -93
- package/lib/project-files/src/common/constants/ENV.ts +0 -19
- package/lib/project-files/src/common/constants/HTTP_STATUS_CODES.ts +0 -81
- package/lib/project-files/src/common/constants/PATHS.ts +0 -15
- package/lib/project-files/src/common/constants/index.ts +0 -11
- package/lib/project-files/src/common/util/misc.ts +0 -11
- package/lib/project-files/src/common/util/route-errors.ts +0 -38
- package/lib/project-files/src/common/util/validators.ts +0 -21
- package/lib/project-files/src/index.ts +0 -27
- package/lib/project-files/src/models/User.ts +0 -69
- package/lib/project-files/src/models/common/types/index.ts +0 -5
- package/lib/project-files/src/public/scripts/http.js +0 -26
- package/lib/project-files/src/public/scripts/users.js +0 -141
- package/lib/project-files/src/public/stylesheets/users.css +0 -48
- package/lib/project-files/src/repos/MockOrm.ts +0 -63
- package/lib/project-files/src/repos/UserRepo.ts +0 -134
- package/lib/project-files/src/repos/database.json +0 -1
- package/lib/project-files/src/repos/database.test.json +0 -1
- package/lib/project-files/src/routes/UserRoutes.ts +0 -69
- package/lib/project-files/src/routes/common/types/index.ts +0 -10
- package/lib/project-files/src/routes/common/util/index.ts +0 -16
- package/lib/project-files/src/routes/index.ts +0 -31
- package/lib/project-files/src/server.ts +0 -86
- package/lib/project-files/src/services/UserService.ts +0 -70
- package/lib/project-files/src/views/users.html +0 -132
- package/lib/project-files/tests/common/types/index.ts +0 -16
- package/lib/project-files/tests/common/util/index.ts +0 -55
- package/lib/project-files/tests/support/setup.ts +0 -26
- package/lib/project-files/tests/users.test.ts +0 -138
- package/lib/project-files/tsconfig.json +0 -35
- package/lib/project-files/tsconfig.prod.json +0 -30
- package/lib/project-files/vitest.config.mts +0 -18
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import logger from 'jet-logger';
|
|
2
|
-
|
|
3
|
-
import ENV from '@src/common/constants/ENV';
|
|
4
|
-
import server from './server';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/******************************************************************************
|
|
8
|
-
Constants
|
|
9
|
-
******************************************************************************/
|
|
10
|
-
|
|
11
|
-
const SERVER_START_MSG = (
|
|
12
|
-
'Express server started on port: ' + ENV.Port.toString()
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/******************************************************************************
|
|
17
|
-
Run
|
|
18
|
-
******************************************************************************/
|
|
19
|
-
|
|
20
|
-
// Start the server
|
|
21
|
-
server.listen(ENV.Port, err => {
|
|
22
|
-
if (!!err) {
|
|
23
|
-
logger.err(err.message);
|
|
24
|
-
} else {
|
|
25
|
-
logger.info(SERVER_START_MSG);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { isString } from 'jet-validators';
|
|
2
|
-
import { parseObject, TParseOnError } from 'jet-validators/utils';
|
|
3
|
-
|
|
4
|
-
import { isRelationalKey, transIsDate } from '@src/common/util/validators';
|
|
5
|
-
import { IModel } from './common/types';
|
|
6
|
-
|
|
7
|
-
/******************************************************************************
|
|
8
|
-
Constants
|
|
9
|
-
******************************************************************************/
|
|
10
|
-
|
|
11
|
-
const DEFAULT_USER_VALS: IUser = {
|
|
12
|
-
id: -1,
|
|
13
|
-
name: '',
|
|
14
|
-
created: new Date(),
|
|
15
|
-
email: '',
|
|
16
|
-
} as const;
|
|
17
|
-
|
|
18
|
-
/******************************************************************************
|
|
19
|
-
Types
|
|
20
|
-
******************************************************************************/
|
|
21
|
-
|
|
22
|
-
export interface IUser extends IModel {
|
|
23
|
-
name: string;
|
|
24
|
-
email: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/******************************************************************************
|
|
28
|
-
Setup
|
|
29
|
-
******************************************************************************/
|
|
30
|
-
|
|
31
|
-
// Initialize the "parseUser" function
|
|
32
|
-
const parseUser = parseObject<IUser>({
|
|
33
|
-
id: isRelationalKey,
|
|
34
|
-
name: isString,
|
|
35
|
-
email: isString,
|
|
36
|
-
created: transIsDate,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
/******************************************************************************
|
|
40
|
-
Functions
|
|
41
|
-
******************************************************************************/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* New user object.
|
|
45
|
-
*/
|
|
46
|
-
function __new__(user?: Partial<IUser>): IUser {
|
|
47
|
-
const defaults = { ...DEFAULT_USER_VALS };
|
|
48
|
-
defaults.created = new Date();
|
|
49
|
-
const retVal = { ...defaults, ...user };
|
|
50
|
-
return parseUser(retVal, errors => {
|
|
51
|
-
throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Check is a user object. For the route validation.
|
|
57
|
-
*/
|
|
58
|
-
function test(arg: unknown, errCb?: TParseOnError): arg is IUser {
|
|
59
|
-
return !!parseUser(arg, errCb);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/******************************************************************************
|
|
63
|
-
Export default
|
|
64
|
-
******************************************************************************/
|
|
65
|
-
|
|
66
|
-
export default {
|
|
67
|
-
new: __new__,
|
|
68
|
-
test,
|
|
69
|
-
} as const;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
var Http = (() => {
|
|
2
|
-
|
|
3
|
-
// Setup request for json
|
|
4
|
-
var getOptions = (verb, data) => {
|
|
5
|
-
var options = {
|
|
6
|
-
dataType: 'json',
|
|
7
|
-
method: verb,
|
|
8
|
-
headers: {
|
|
9
|
-
'Accept': 'application/json',
|
|
10
|
-
'Content-Type': 'application/json',
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
if (!!data) {
|
|
14
|
-
options.body = JSON.stringify(data);
|
|
15
|
-
}
|
|
16
|
-
return options;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// Set Http methods
|
|
20
|
-
return {
|
|
21
|
-
get: (path) => fetch(path, getOptions('GET')),
|
|
22
|
-
post: (path, data) => fetch(path, getOptions('POST', data)),
|
|
23
|
-
put: (path, data) => fetch(path, getOptions('PUT', data)),
|
|
24
|
-
delete: (path) => fetch(path, getOptions('DELETE')),
|
|
25
|
-
};
|
|
26
|
-
})();
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
|
-
/******************************************************************************
|
|
4
|
-
Constants
|
|
5
|
-
******************************************************************************/
|
|
6
|
-
|
|
7
|
-
const DateFormatter = new Intl.DateTimeFormat('en-US', {
|
|
8
|
-
year: 'numeric',
|
|
9
|
-
month: '2-digit',
|
|
10
|
-
day: '2-digit',
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const formatDate = (date) => DateFormatter.format(new Date(date));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/******************************************************************************
|
|
17
|
-
Run
|
|
18
|
-
******************************************************************************/
|
|
19
|
-
|
|
20
|
-
// Start
|
|
21
|
-
displayUsers();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/******************************************************************************
|
|
25
|
-
Functions
|
|
26
|
-
******************************************************************************/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Call api
|
|
30
|
-
*/
|
|
31
|
-
function displayUsers() {
|
|
32
|
-
Http
|
|
33
|
-
.get('/api/users/all')
|
|
34
|
-
.then(resp => resp.json())
|
|
35
|
-
.then(resp => {
|
|
36
|
-
var allUsersTemplate = document.getElementById('all-users-template'),
|
|
37
|
-
allUsersTemplateHtml = allUsersTemplate.innerHTML,
|
|
38
|
-
template = Handlebars.compile(allUsersTemplateHtml);
|
|
39
|
-
var allUsersAnchor = document.getElementById('all-users-anchor');
|
|
40
|
-
allUsersAnchor.innerHTML = template({
|
|
41
|
-
users: resp.users.map(user => ({
|
|
42
|
-
...user,
|
|
43
|
-
createdFormatted: formatDate(user.created),
|
|
44
|
-
})),
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Setup event listener for button click
|
|
50
|
-
document.addEventListener('click', event => {
|
|
51
|
-
event.preventDefault();
|
|
52
|
-
var ele = event.target;
|
|
53
|
-
if (ele.matches('#add-user-btn')) {
|
|
54
|
-
addUser();
|
|
55
|
-
} else if (ele.matches('.edit-user-btn')) {
|
|
56
|
-
showEditView(ele.parentNode.parentNode);
|
|
57
|
-
} else if (ele.matches('.cancel-edit-btn')) {
|
|
58
|
-
cancelEdit(ele.parentNode.parentNode);
|
|
59
|
-
} else if (ele.matches('.submit-edit-btn')) {
|
|
60
|
-
submitEdit(ele);
|
|
61
|
-
} else if (ele.matches('.delete-user-btn')) {
|
|
62
|
-
deleteUser(ele);
|
|
63
|
-
}
|
|
64
|
-
}, false);
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Add a new user.
|
|
68
|
-
*/
|
|
69
|
-
function addUser() {
|
|
70
|
-
var nameInput = document.getElementById('name-input');
|
|
71
|
-
var emailInput = document.getElementById('email-input');
|
|
72
|
-
var data = {
|
|
73
|
-
user: {
|
|
74
|
-
id: -1,
|
|
75
|
-
name: nameInput.value,
|
|
76
|
-
email: emailInput.value,
|
|
77
|
-
created: new Date(),
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
// Call api
|
|
81
|
-
Http
|
|
82
|
-
.post('/api/users/add', data)
|
|
83
|
-
.then(() => {
|
|
84
|
-
nameInput.value = '';
|
|
85
|
-
emailInput.value = '';
|
|
86
|
-
displayUsers();
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Show edit view.
|
|
92
|
-
*/
|
|
93
|
-
function showEditView(userEle) {
|
|
94
|
-
var normalView = userEle.getElementsByClassName('normal-view')[0];
|
|
95
|
-
var editView = userEle.getElementsByClassName('edit-view')[0];
|
|
96
|
-
normalView.style.display = 'none';
|
|
97
|
-
editView.style.display = 'block';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Cancel edit.
|
|
102
|
-
*/
|
|
103
|
-
function cancelEdit(userEle) {
|
|
104
|
-
var normalView = userEle.getElementsByClassName('normal-view')[0];
|
|
105
|
-
var editView = userEle.getElementsByClassName('edit-view')[0];
|
|
106
|
-
normalView.style.display = 'block';
|
|
107
|
-
editView.style.display = 'none';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Submit edit.
|
|
112
|
-
*/
|
|
113
|
-
function submitEdit(ele) {
|
|
114
|
-
var userEle = ele.parentNode.parentNode;
|
|
115
|
-
var nameInput = userEle.getElementsByClassName('name-edit-input')[0];
|
|
116
|
-
var emailInput = userEle.getElementsByClassName('email-edit-input')[0];
|
|
117
|
-
var id = ele.getAttribute('data-user-id');
|
|
118
|
-
var created = ele.getAttribute('data-user-created');
|
|
119
|
-
console.log(ele, created)
|
|
120
|
-
var data = {
|
|
121
|
-
user: {
|
|
122
|
-
id: Number(id),
|
|
123
|
-
name: nameInput.value,
|
|
124
|
-
email: emailInput.value,
|
|
125
|
-
created: new Date(created),
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
Http
|
|
129
|
-
.put('/api/users/update', data)
|
|
130
|
-
.then(() => displayUsers());
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Delete a user
|
|
135
|
-
*/
|
|
136
|
-
function deleteUser(ele) {
|
|
137
|
-
var id = ele.getAttribute('data-user-id');
|
|
138
|
-
Http
|
|
139
|
-
.delete('/api/users/delete/' + id)
|
|
140
|
-
.then(() => displayUsers());
|
|
141
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
body {
|
|
2
|
-
padding: 100px;
|
|
3
|
-
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
body .users-column {
|
|
7
|
-
display: inline-block;
|
|
8
|
-
margin-right: 2em;
|
|
9
|
-
vertical-align: top;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
body .users-column .column-header {
|
|
13
|
-
padding-bottom: 5px;
|
|
14
|
-
font-weight: 700;
|
|
15
|
-
font-size: 1.2em;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/** Add User Column **/
|
|
20
|
-
|
|
21
|
-
body .add-user-col input {
|
|
22
|
-
margin-bottom: 10px;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
body .add-user-col #add-user-btn {
|
|
26
|
-
margin-top: 2px;
|
|
27
|
-
margin-bottom: 10px;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/** Users Display Column **/
|
|
32
|
-
|
|
33
|
-
.email-edit {
|
|
34
|
-
padding-bottom: 8px;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
body .users-column .user-display-ele {
|
|
38
|
-
padding-bottom: 10px;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
body .users-column .user-display-ele button {
|
|
42
|
-
margin-top: 2px;
|
|
43
|
-
margin-bottom: 10px;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
body .users-column .user-display-ele .edit-view {
|
|
47
|
-
display: none;
|
|
48
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import jsonfile from 'jsonfile';
|
|
2
|
-
|
|
3
|
-
import ENV from '@src/common/constants/ENV';
|
|
4
|
-
import { NODE_ENVS } from '@src/common/constants';
|
|
5
|
-
import { IUser } from '@src/models/User';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/******************************************************************************
|
|
9
|
-
Constants
|
|
10
|
-
******************************************************************************/
|
|
11
|
-
|
|
12
|
-
const DB_FILE_NAME = (
|
|
13
|
-
ENV.NodeEnv === NODE_ENVS.Test
|
|
14
|
-
? 'database.test.json'
|
|
15
|
-
: 'database.json'
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/******************************************************************************
|
|
20
|
-
Types
|
|
21
|
-
******************************************************************************/
|
|
22
|
-
|
|
23
|
-
interface IDatabase {
|
|
24
|
-
users: IUser[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/******************************************************************************
|
|
29
|
-
Functions
|
|
30
|
-
******************************************************************************/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Fetch the json from the file.
|
|
34
|
-
*/
|
|
35
|
-
function openDb(): Promise<IDatabase> {
|
|
36
|
-
return jsonfile.readFile(__dirname + '/' + DB_FILE_NAME) as
|
|
37
|
-
Promise<IDatabase>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Update the file.
|
|
42
|
-
*/
|
|
43
|
-
function saveDb(db: IDatabase): Promise<void> {
|
|
44
|
-
return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), db);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Empty the database
|
|
49
|
-
*/
|
|
50
|
-
function cleanDb(): Promise<void> {
|
|
51
|
-
return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), {});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/******************************************************************************
|
|
56
|
-
Export default
|
|
57
|
-
******************************************************************************/
|
|
58
|
-
|
|
59
|
-
export default {
|
|
60
|
-
openDb,
|
|
61
|
-
saveDb,
|
|
62
|
-
cleanDb,
|
|
63
|
-
} as const;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { IUser } from '@src/models/User';
|
|
2
|
-
import { getRandomInt } from '@src/common/util/misc';
|
|
3
|
-
|
|
4
|
-
import orm from './MockOrm';
|
|
5
|
-
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Functions
|
|
8
|
-
******************************************************************************/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get one user.
|
|
12
|
-
*/
|
|
13
|
-
async function getOne(email: string): Promise<IUser | null> {
|
|
14
|
-
const db = await orm.openDb();
|
|
15
|
-
for (const user of db.users) {
|
|
16
|
-
if (user.email === email) {
|
|
17
|
-
return user;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* See if a user with the given id exists.
|
|
25
|
-
*/
|
|
26
|
-
async function persists(id: number): Promise<boolean> {
|
|
27
|
-
const db = await orm.openDb();
|
|
28
|
-
for (const user of db.users) {
|
|
29
|
-
if (user.id === id) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Get all users.
|
|
38
|
-
*/
|
|
39
|
-
async function getAll(): Promise<IUser[]> {
|
|
40
|
-
const db = await orm.openDb();
|
|
41
|
-
return db.users;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Add one user.
|
|
46
|
-
*/
|
|
47
|
-
async function add(user: IUser): Promise<void> {
|
|
48
|
-
const db = await orm.openDb();
|
|
49
|
-
user.id = getRandomInt();
|
|
50
|
-
db.users.push(user);
|
|
51
|
-
return orm.saveDb(db);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Update a user.
|
|
56
|
-
*/
|
|
57
|
-
async function update(user: IUser): Promise<void> {
|
|
58
|
-
const db = await orm.openDb();
|
|
59
|
-
for (let i = 0; i < db.users.length; i++) {
|
|
60
|
-
if (db.users[i].id === user.id) {
|
|
61
|
-
const dbUser = db.users[i];
|
|
62
|
-
db.users[i] = {
|
|
63
|
-
...dbUser,
|
|
64
|
-
name: user.name,
|
|
65
|
-
email: user.email,
|
|
66
|
-
};
|
|
67
|
-
return orm.saveDb(db);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Delete one user.
|
|
74
|
-
*/
|
|
75
|
-
async function delete_(id: number): Promise<void> {
|
|
76
|
-
const db = await orm.openDb();
|
|
77
|
-
for (let i = 0; i < db.users.length; i++) {
|
|
78
|
-
if (db.users[i].id === id) {
|
|
79
|
-
db.users.splice(i, 1);
|
|
80
|
-
return orm.saveDb(db);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// **** Unit-Tests Only **** //
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Delete every user record.
|
|
90
|
-
*
|
|
91
|
-
* @internal
|
|
92
|
-
* Test-only helper. Do not use in production code.
|
|
93
|
-
*/
|
|
94
|
-
async function deleteAllUsers(): Promise<void> {
|
|
95
|
-
const db = await orm.openDb();
|
|
96
|
-
db.users = [];
|
|
97
|
-
return orm.saveDb(db);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Insert multiple users. Can't do multiple at once cause using a plain file
|
|
102
|
-
* for now.
|
|
103
|
-
*
|
|
104
|
-
* @internal
|
|
105
|
-
* Test-only helper. Do not use in production code.
|
|
106
|
-
*/
|
|
107
|
-
async function insertMult(
|
|
108
|
-
users: IUser[] | readonly IUser[],
|
|
109
|
-
): Promise<IUser[]> {
|
|
110
|
-
const db = await orm.openDb(),
|
|
111
|
-
usersF = [ ...users ];
|
|
112
|
-
for (const user of usersF) {
|
|
113
|
-
user.id = getRandomInt();
|
|
114
|
-
user.created = new Date();
|
|
115
|
-
}
|
|
116
|
-
db.users = [ ...db.users, ...users ];
|
|
117
|
-
await orm.saveDb(db);
|
|
118
|
-
return usersF;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/******************************************************************************
|
|
122
|
-
Export default
|
|
123
|
-
******************************************************************************/
|
|
124
|
-
|
|
125
|
-
export default {
|
|
126
|
-
getOne,
|
|
127
|
-
persists,
|
|
128
|
-
getAll,
|
|
129
|
-
add,
|
|
130
|
-
update,
|
|
131
|
-
delete: delete_,
|
|
132
|
-
deleteAllUsers,
|
|
133
|
-
insertMult,
|
|
134
|
-
} as const;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"users":[{"id":366115170645,"name":"Sean Maxwell","email":"smaxwell@example.com","created":"2024-03-22T05:14:36.252Z"},{"id":310946254456,"name":"John Smith","email":"john.smith@example.com","created":"2024-03-22T05:20:55.079Z"},{"id":143027113460,"name":"Gordan Freeman","email":"nova@prospect.com","created":"2024-03-22T05:42:18.895Z"}]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"users":[{"id":967269206317,"name":"Bill","created":"2025-12-17T09:55:17.960Z","email":"sean.maxwell@gmail.com"},{"id":3025435078,"name":"John Smith","created":"2025-12-17T09:55:17.960Z","email":"john.smith@gmail.com"},{"id":786429791732,"name":"Gordan Freeman","created":"2025-12-17T09:55:17.960Z","email":"gordan.freeman@gmail.com"}]}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { isNumber } from 'jet-validators';
|
|
2
|
-
import { transform } from 'jet-validators/utils';
|
|
3
|
-
|
|
4
|
-
import HTTP_STATUS_CODES from '@src/common/constants/HTTP_STATUS_CODES';
|
|
5
|
-
import UserService from '@src/services/UserService';
|
|
6
|
-
import User from '@src/models/User';
|
|
7
|
-
|
|
8
|
-
import { IReq, IRes } from './common/types';
|
|
9
|
-
import { parseReq } from './common/util';
|
|
10
|
-
|
|
11
|
-
/******************************************************************************
|
|
12
|
-
Constants
|
|
13
|
-
******************************************************************************/
|
|
14
|
-
|
|
15
|
-
const Validators = {
|
|
16
|
-
add: parseReq({ user: User.test }),
|
|
17
|
-
update: parseReq({ user: User.test }),
|
|
18
|
-
delete: parseReq({ id: transform(Number, isNumber) }),
|
|
19
|
-
} as const;
|
|
20
|
-
|
|
21
|
-
/******************************************************************************
|
|
22
|
-
Functions
|
|
23
|
-
******************************************************************************/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get all users.
|
|
27
|
-
*/
|
|
28
|
-
async function getAll(_: IReq, res: IRes) {
|
|
29
|
-
const users = await UserService.getAll();
|
|
30
|
-
res.status(HTTP_STATUS_CODES.Ok).json({ users });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Add one user.
|
|
35
|
-
*/
|
|
36
|
-
async function add(req: IReq, res: IRes) {
|
|
37
|
-
const { user } = Validators.add(req.body);
|
|
38
|
-
await UserService.addOne(user);
|
|
39
|
-
res.status(HTTP_STATUS_CODES.Created).end();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Update one user.
|
|
44
|
-
*/
|
|
45
|
-
async function update(req: IReq, res: IRes) {
|
|
46
|
-
const { user } = Validators.update(req.body);
|
|
47
|
-
await UserService.updateOne(user);
|
|
48
|
-
res.status(HTTP_STATUS_CODES.Ok).end();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Delete one user.
|
|
53
|
-
*/
|
|
54
|
-
async function delete_(req: IReq, res: IRes) {
|
|
55
|
-
const { id } = Validators.delete(req.params);
|
|
56
|
-
await UserService.delete(id);
|
|
57
|
-
res.status(HTTP_STATUS_CODES.Ok).end();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/******************************************************************************
|
|
61
|
-
Export default
|
|
62
|
-
******************************************************************************/
|
|
63
|
-
|
|
64
|
-
export default {
|
|
65
|
-
getAll,
|
|
66
|
-
add,
|
|
67
|
-
update,
|
|
68
|
-
delete: delete_,
|
|
69
|
-
} as const;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Response, Request } from 'express';
|
|
2
|
-
|
|
3
|
-
/******************************************************************************
|
|
4
|
-
Types
|
|
5
|
-
******************************************************************************/
|
|
6
|
-
|
|
7
|
-
type TRecord = Record<string, unknown>;
|
|
8
|
-
export type IReq = Request<TRecord, void, TRecord, TRecord>;
|
|
9
|
-
export type IRes = Response<unknown, TRecord>;
|
|
10
|
-
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { parseObject, TSchema } from 'jet-validators/utils';
|
|
2
|
-
import { ValidationError } from '@src/common/util/route-errors';
|
|
3
|
-
|
|
4
|
-
/******************************************************************************
|
|
5
|
-
Functions
|
|
6
|
-
******************************************************************************/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Throw a "ParseObjError" when "parseObject" fails. Also extract a nested
|
|
10
|
-
* "ParseObjError" and add it to the nestedErrors array.
|
|
11
|
-
*/
|
|
12
|
-
export function parseReq<U extends TSchema>(schema: U) {
|
|
13
|
-
return parseObject(schema, errors => {
|
|
14
|
-
throw new ValidationError(errors);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
|
|
3
|
-
import PATHS from '@src/common/constants/PATHS';
|
|
4
|
-
import UserRoutes from './UserRoutes';
|
|
5
|
-
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Setup
|
|
8
|
-
******************************************************************************/
|
|
9
|
-
|
|
10
|
-
const apiRouter = Router();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// ** Add UserRouter ** //
|
|
14
|
-
|
|
15
|
-
// Init router
|
|
16
|
-
const userRouter = Router();
|
|
17
|
-
|
|
18
|
-
// Get all users
|
|
19
|
-
userRouter.get(PATHS.Users.Get, UserRoutes.getAll);
|
|
20
|
-
userRouter.post(PATHS.Users.Add, UserRoutes.add);
|
|
21
|
-
userRouter.put(PATHS.Users.Update, UserRoutes.update);
|
|
22
|
-
userRouter.delete(PATHS.Users.Delete, UserRoutes.delete);
|
|
23
|
-
|
|
24
|
-
// Add UserRouter
|
|
25
|
-
apiRouter.use(PATHS.Users._, userRouter);
|
|
26
|
-
|
|
27
|
-
/******************************************************************************
|
|
28
|
-
Export default
|
|
29
|
-
******************************************************************************/
|
|
30
|
-
|
|
31
|
-
export default apiRouter;
|