express-generator-typescript 1.10.1 → 2.0.0
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.md +37 -25
- package/bin/cli.js +2 -15
- package/lib/cli.js +1 -15
- package/lib/express-generator-typescript.js +15 -23
- package/lib/project-files/.eslintrc.json +15 -2
- package/lib/project-files/build.ts +2 -2
- package/lib/project-files/package.json +15 -5
- package/lib/project-files/spec/nodemon.json +1 -1
- package/lib/{auth-proj → project-files}/spec/support/login-agent.ts +0 -0
- package/lib/{auth-proj → project-files}/spec/tests/auth.spec.ts +18 -32
- package/lib/project-files/spec/tests/users.spec.ts +31 -22
- package/lib/project-files/spec/types/supertest/index.d.ts +14 -0
- package/lib/project-files/src/models/user-model.ts +17 -2
- package/lib/project-files/src/pre-start/env/development.env +9 -0
- package/lib/project-files/src/pre-start/env/production.env +10 -0
- package/lib/project-files/src/pre-start/env/test.env +9 -0
- package/lib/{auth-proj → project-files}/src/public/scripts/http.js +0 -0
- package/lib/{auth-proj → project-files}/src/public/scripts/login.js +0 -0
- package/lib/{auth-proj → project-files}/src/public/scripts/users.js +0 -0
- package/lib/{auth-proj → project-files}/src/public/stylesheets/login.css +0 -0
- package/lib/{auth-proj → project-files}/src/public/stylesheets/users.css +0 -0
- package/lib/project-files/src/repos/user-repo.ts +7 -7
- package/lib/project-files/src/routes/api.ts +9 -6
- package/lib/{auth-proj → project-files}/src/routes/auth-router.ts +11 -4
- package/lib/{auth-proj → project-files}/src/routes/middleware.ts +7 -8
- package/lib/project-files/src/routes/user-router.ts +12 -16
- package/lib/project-files/src/server.ts +82 -73
- package/lib/{auth-proj → project-files}/src/services/auth-service.ts +0 -0
- package/lib/project-files/src/services/user-service.ts +8 -8
- package/lib/project-files/src/shared/env-vars.ts +18 -0
- package/lib/project-files/src/shared/errors.ts +11 -0
- package/lib/project-files/src/types/express/index.d.ts +27 -5
- package/lib/{auth-proj → project-files}/src/util/jwt-util.ts +4 -9
- package/lib/{auth-proj → project-files}/src/views/login.html +0 -0
- package/lib/{auth-proj → project-files}/src/views/users.html +0 -0
- package/lib/project-files/tsconfig.json +3 -0
- package/package.json +1 -1
- package/chat-screenshot.png +0 -0
- package/lib/auth-proj/.eslintignore +0 -1
- package/lib/auth-proj/.eslintrc.json +0 -27
- package/lib/auth-proj/build.ts +0 -64
- package/lib/auth-proj/gitignore +0 -3
- package/lib/auth-proj/package.json +0 -73
- package/lib/auth-proj/spec/index.ts +0 -57
- package/lib/auth-proj/spec/loadEnv.ts +0 -10
- package/lib/auth-proj/spec/nodemon.json +0 -6
- package/lib/auth-proj/spec/support/jasmine.json +0 -11
- package/lib/auth-proj/spec/tests/users.spec.ts +0 -283
- package/lib/auth-proj/src/index.ts +0 -14
- package/lib/auth-proj/src/models/user-model.ts +0 -56
- package/lib/auth-proj/src/pre-start/env/development.env +0 -23
- package/lib/auth-proj/src/pre-start/env/production.env +0 -24
- package/lib/auth-proj/src/pre-start/env/test.env +0 -23
- package/lib/auth-proj/src/pre-start/index.ts +0 -28
- package/lib/auth-proj/src/repos/database.json +0 -1
- package/lib/auth-proj/src/repos/mock-orm.ts +0 -41
- package/lib/auth-proj/src/repos/user-repo.ts +0 -88
- package/lib/auth-proj/src/routes/api.ts +0 -17
- package/lib/auth-proj/src/routes/user-router.ts +0 -78
- package/lib/auth-proj/src/server.ts +0 -82
- package/lib/auth-proj/src/services/user-service.ts +0 -52
- package/lib/auth-proj/src/shared/env-vars.ts +0 -20
- package/lib/auth-proj/src/shared/errors.ts +0 -45
- package/lib/auth-proj/src/shared/functions.ts +0 -18
- package/lib/auth-proj/src/types/express/index.d.ts +0 -23
- package/lib/auth-proj/tsconfig.json +0 -100
- package/lib/auth-proj/tsconfig.prod.json +0 -11
- package/lib/project-files/src/public/scripts/index.js +0 -183
- package/lib/project-files/src/public/stylesheets/style.css +0 -33
- package/lib/project-files/src/views/index.html +0 -31
- package/lib/socket-io/.eslintignore +0 -1
- package/lib/socket-io/.eslintrc.json +0 -27
- package/lib/socket-io/build.ts +0 -64
- package/lib/socket-io/gitignore +0 -3
- package/lib/socket-io/package.json +0 -75
- package/lib/socket-io/spec/index.ts +0 -57
- package/lib/socket-io/spec/loadEnv.ts +0 -10
- package/lib/socket-io/spec/nodemon.json +0 -6
- package/lib/socket-io/spec/support/jasmine.json +0 -11
- package/lib/socket-io/spec/support/login-agent.ts +0 -49
- package/lib/socket-io/spec/tests/auth.spec.ts +0 -159
- package/lib/socket-io/spec/tests/chat.spec.ts +0 -150
- package/lib/socket-io/spec/tests/users.spec.ts +0 -283
- package/lib/socket-io/src/index.ts +0 -14
- package/lib/socket-io/src/models/user-model.ts +0 -56
- package/lib/socket-io/src/pre-start/env/development.env +0 -23
- package/lib/socket-io/src/pre-start/env/production.env +0 -24
- package/lib/socket-io/src/pre-start/env/test.env +0 -23
- package/lib/socket-io/src/pre-start/index.ts +0 -28
- package/lib/socket-io/src/public/scripts/chat.js +0 -87
- package/lib/socket-io/src/public/scripts/http.js +0 -24
- package/lib/socket-io/src/public/scripts/index.js +0 -16
- package/lib/socket-io/src/public/scripts/login.js +0 -17
- package/lib/socket-io/src/public/scripts/users.js +0 -148
- package/lib/socket-io/src/public/stylesheets/chat.css +0 -43
- package/lib/socket-io/src/public/stylesheets/index.css +0 -13
- package/lib/socket-io/src/public/stylesheets/login.css +0 -20
- package/lib/socket-io/src/public/stylesheets/users.css +0 -40
- package/lib/socket-io/src/repos/database.json +0 -38
- package/lib/socket-io/src/repos/mock-orm.ts +0 -41
- package/lib/socket-io/src/repos/user-repo.ts +0 -88
- package/lib/socket-io/src/routes/api.ts +0 -19
- package/lib/socket-io/src/routes/auth-router.ts +0 -67
- package/lib/socket-io/src/routes/chat-router.ts +0 -88
- package/lib/socket-io/src/routes/middleware.ts +0 -55
- package/lib/socket-io/src/routes/user-router.ts +0 -76
- package/lib/socket-io/src/server.ts +0 -100
- package/lib/socket-io/src/services/auth-service.ts +0 -38
- package/lib/socket-io/src/services/user-service.ts +0 -52
- package/lib/socket-io/src/shared/env-vars.ts +0 -20
- package/lib/socket-io/src/shared/errors.ts +0 -56
- package/lib/socket-io/src/shared/functions.ts +0 -18
- package/lib/socket-io/src/types/express/index.d.ts +0 -23
- package/lib/socket-io/src/util/jwt-util.ts +0 -52
- package/lib/socket-io/src/views/chat.html +0 -51
- package/lib/socket-io/src/views/login.html +0 -35
- package/lib/socket-io/src/views/users.html +0 -47
- package/lib/socket-io/tsconfig.json +0 -100
- package/lib/socket-io/tsconfig.prod.json +0 -11
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
## Environment ##
|
|
2
|
-
NODE_ENV=production
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Server ##
|
|
6
|
-
PORT=8081
|
|
7
|
-
HOST=localhost
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Setup jet-logger ##
|
|
11
|
-
JET_LOGGER_MODE=FILE
|
|
12
|
-
JET_LOGGER_FILEPATH=jet-logger.log
|
|
13
|
-
JET_LOGGER_TIMESTAMP=TRUE
|
|
14
|
-
JET_LOGGER_FORMAT=LINE
|
|
15
|
-
|
|
16
|
-
## Authentication ##
|
|
17
|
-
# SECURE_COOKIE 'false' here for demo-ing. But ideally should be true.
|
|
18
|
-
COOKIE_DOMAIN=localhost
|
|
19
|
-
COOKIE_PATH=/
|
|
20
|
-
SECURE_COOKIE=false
|
|
21
|
-
JWT_SECRET=xxxxxxxxxxxxxx
|
|
22
|
-
COOKIE_SECRET=xxxxxxxxxxxxxx
|
|
23
|
-
# expires in 3 days
|
|
24
|
-
COOKIE_EXP=259200000
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
## Environment ##
|
|
2
|
-
NODE_ENV=test
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Server ##
|
|
6
|
-
PORT=4000
|
|
7
|
-
HOST=localhost
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Setup jet-logger ##
|
|
11
|
-
JET_LOGGER_MODE=CONSOLE
|
|
12
|
-
JET_LOGGER_FILEPATH=jet-logger.log
|
|
13
|
-
JET_LOGGER_TIMESTAMP=TRUE
|
|
14
|
-
JET_LOGGER_FORMAT=LINE
|
|
15
|
-
|
|
16
|
-
## Authentication ##
|
|
17
|
-
COOKIE_DOMAIN=localhost
|
|
18
|
-
COOKIE_PATH=/
|
|
19
|
-
SECURE_COOKIE=false
|
|
20
|
-
JWT_SECRET=xxxxxxxxxxxxxx
|
|
21
|
-
COOKIE_SECRET=xxxxxxxxxxxxxx
|
|
22
|
-
# expires in 3 days
|
|
23
|
-
COOKIE_EXP=259200000
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pre-start is where we want to place things that must run BEFORE the express server is started.
|
|
3
|
-
* This is useful for environment variables, command-line arguments, and cron-jobs.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import dotenv from 'dotenv';
|
|
8
|
-
import commandLineArgs from 'command-line-args';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// Setup command line options
|
|
12
|
-
const options = commandLineArgs([
|
|
13
|
-
{
|
|
14
|
-
name: 'env',
|
|
15
|
-
alias: 'e',
|
|
16
|
-
defaultValue: 'development',
|
|
17
|
-
type: String,
|
|
18
|
-
},
|
|
19
|
-
]);
|
|
20
|
-
|
|
21
|
-
// Set the env file
|
|
22
|
-
const result2 = dotenv.config({
|
|
23
|
-
path: path.join(__dirname, `env/${String(options.env)}.env`),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (result2.error) {
|
|
27
|
-
throw result2.error;
|
|
28
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// Start
|
|
2
|
-
(() => {
|
|
3
|
-
// Setup socket-io main connection
|
|
4
|
-
console.log('Connecting to socket-io');
|
|
5
|
-
const socket = io('http://localhost:3000');
|
|
6
|
-
socket.on('connect', () => {
|
|
7
|
-
socketIo = socket;
|
|
8
|
-
console.log('Socket-io connected');
|
|
9
|
-
// Connect to the room
|
|
10
|
-
connectToRm(socket.id);
|
|
11
|
-
setupSendMsgListener(socket.id)
|
|
12
|
-
receiveMessage(socket);
|
|
13
|
-
});
|
|
14
|
-
})();
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Connect to the socket-io room for the chat window.
|
|
18
|
-
*/
|
|
19
|
-
function connectToRm(socketId) {
|
|
20
|
-
console.log('Connecting to socket room');
|
|
21
|
-
Http
|
|
22
|
-
.get('/api/chat/connect-socket-room/' + socketId)
|
|
23
|
-
.then(() => {
|
|
24
|
-
console.log('Connected to socket room');
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Send a message.
|
|
30
|
-
*/
|
|
31
|
-
function setupSendMsgListener(socketId) {
|
|
32
|
-
document.addEventListener('click', (event) => {
|
|
33
|
-
event.preventDefault();
|
|
34
|
-
var ele = event.target;
|
|
35
|
-
// Detect btn click
|
|
36
|
-
if (ele.matches('#send-msg-btn')) {
|
|
37
|
-
const inputEle = document.getElementById('send-msg-input');
|
|
38
|
-
const message = inputEle.value;
|
|
39
|
-
inputEle.value = '';
|
|
40
|
-
// Call API
|
|
41
|
-
Http.post('/api/chat/emit-message', {
|
|
42
|
-
socketId,
|
|
43
|
-
message,
|
|
44
|
-
})
|
|
45
|
-
.then(resp => resp.json())
|
|
46
|
-
.then((resp) =>
|
|
47
|
-
addMessage({
|
|
48
|
-
senderName: resp.senderName,
|
|
49
|
-
timestamp: Date.now(),
|
|
50
|
-
content: message,
|
|
51
|
-
})
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Receive a socket message.
|
|
59
|
-
*/
|
|
60
|
-
function receiveMessage(socket) {
|
|
61
|
-
socket.on('emit-msg', (msg) => {
|
|
62
|
-
addMessage(msg);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Get the html content for a single chat message.
|
|
68
|
-
*/
|
|
69
|
-
function addMessage(msg) {
|
|
70
|
-
const chatWindow = document.getElementById('chat-window');
|
|
71
|
-
const msgEle = `
|
|
72
|
-
<div class="chat-msg">
|
|
73
|
-
<div>
|
|
74
|
-
<span class="msg-name">
|
|
75
|
-
${msg.senderName}
|
|
76
|
-
</span>
|
|
77
|
-
<span class="msg-timestamp">
|
|
78
|
-
${moment(msg.timestamp).format('MM/DD/YYYY h:mm:ssa')}
|
|
79
|
-
</span>
|
|
80
|
-
</div>
|
|
81
|
-
<div>
|
|
82
|
-
${msg.content}
|
|
83
|
-
</div>
|
|
84
|
-
</div>
|
|
85
|
-
`;
|
|
86
|
-
chatWindow.innerHTML += msgEle;
|
|
87
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
var Http = (() => {
|
|
2
|
-
// Setup request for json
|
|
3
|
-
var getOptions = (verb, data) => {
|
|
4
|
-
var options = {
|
|
5
|
-
dataType: 'json',
|
|
6
|
-
method: verb,
|
|
7
|
-
headers: {
|
|
8
|
-
'Accept': 'application/json',
|
|
9
|
-
'Content-Type': 'application/json',
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
if (data) {
|
|
13
|
-
options.body = JSON.stringify(data);
|
|
14
|
-
}
|
|
15
|
-
return options;
|
|
16
|
-
};
|
|
17
|
-
// Set Http methods
|
|
18
|
-
return {
|
|
19
|
-
get: (path) => fetch(path, getOptions('GET')),
|
|
20
|
-
post: (path, data) => fetch(path, getOptions('POST', data)),
|
|
21
|
-
put: (path, data) => fetch(path, getOptions('PUT', data)),
|
|
22
|
-
delete: (path) => fetch(path, getOptions('DELETE')),
|
|
23
|
-
};
|
|
24
|
-
})();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Listen to clicks in the headers
|
|
2
|
-
document.addEventListener('click', function (event) {
|
|
3
|
-
event.preventDefault();
|
|
4
|
-
const ele = event.target;
|
|
5
|
-
if (ele.matches('.nav-users-btn')) {
|
|
6
|
-
window.location.href = '/users';
|
|
7
|
-
} else if (ele.matches('.nav-chat-btn')) {
|
|
8
|
-
window.location.href = '/chat';
|
|
9
|
-
} else if (ele.matches('.logout-btn')) {
|
|
10
|
-
Http
|
|
11
|
-
.get('/api/auth/logout')
|
|
12
|
-
.then(() => {
|
|
13
|
-
window.location.href = '/';
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}, false);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Setup listeners
|
|
2
|
-
document.addEventListener('click', (event) => {
|
|
3
|
-
event.preventDefault();
|
|
4
|
-
if (event.target.matches('#login-btn')) {
|
|
5
|
-
var emailInput = document.getElementById('email-input');
|
|
6
|
-
var pwdInput = document.getElementById('pwd-input');
|
|
7
|
-
var data = {
|
|
8
|
-
email: emailInput.value,
|
|
9
|
-
password: pwdInput.value,
|
|
10
|
-
};
|
|
11
|
-
Http
|
|
12
|
-
.post('/api/auth/login', data)
|
|
13
|
-
.then(() => {
|
|
14
|
-
window.location.href = '/users';
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}, false);
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
// ***** Start **** //
|
|
2
|
-
|
|
3
|
-
displayUsers();
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// **** Fetch and display users **** //
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Call api
|
|
10
|
-
*/
|
|
11
|
-
function displayUsers() {
|
|
12
|
-
Http
|
|
13
|
-
.get('/api/users/all')
|
|
14
|
-
.then(resp => resp.json())
|
|
15
|
-
.then((resp) => {
|
|
16
|
-
var allUsers = resp.users;
|
|
17
|
-
// Empty the anchor
|
|
18
|
-
var allUsersAnchor = document.getElementById('all-users-anchor');
|
|
19
|
-
allUsersAnchor.innerHTML = '';
|
|
20
|
-
// Append users to anchor
|
|
21
|
-
allUsers.forEach((user) => {
|
|
22
|
-
allUsersAnchor.innerHTML += getUserDisplayEle(user);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Get user display element.
|
|
29
|
-
*/
|
|
30
|
-
function getUserDisplayEle(user) {
|
|
31
|
-
return (
|
|
32
|
-
`<div class='user-display-ele'>
|
|
33
|
-
|
|
34
|
-
<div class='normal-view'>
|
|
35
|
-
<div>Name: ${user.name}</div>
|
|
36
|
-
<div>Email: ${user.email}</div>
|
|
37
|
-
<button class='edit-user-btn' data-user-id='${user.id}'>
|
|
38
|
-
Edit
|
|
39
|
-
</button>
|
|
40
|
-
<button class='delete-user-btn' data-user-id='${user.id}'>
|
|
41
|
-
Delete
|
|
42
|
-
</button>
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
<div class='edit-view'>
|
|
46
|
-
<div>
|
|
47
|
-
Name: <input class='name-edit-input' value='${user.name}'>
|
|
48
|
-
</div>
|
|
49
|
-
<div>
|
|
50
|
-
Email: <input class='email-edit-input' value='${user.email}'>
|
|
51
|
-
</div>
|
|
52
|
-
<button class='submit-edit-btn' data-user-id='${user.id}'>
|
|
53
|
-
Submit
|
|
54
|
-
</button>
|
|
55
|
-
<button class='cancel-edit-btn' data-user-id='${user.id}'>
|
|
56
|
-
Cancel
|
|
57
|
-
</button>
|
|
58
|
-
</div>
|
|
59
|
-
</div>`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// **** Add, Edit, and Delete Users **** //
|
|
65
|
-
|
|
66
|
-
// Setup event listeners
|
|
67
|
-
document.addEventListener('click', (event) => {
|
|
68
|
-
event.preventDefault();
|
|
69
|
-
var ele = event.target;
|
|
70
|
-
if (ele.matches('#add-user-btn')) {
|
|
71
|
-
addUser();
|
|
72
|
-
} else if (ele.matches('.edit-user-btn')) {
|
|
73
|
-
showEditView(ele.parentNode.parentNode);
|
|
74
|
-
} else if (ele.matches('.cancel-edit-btn')) {
|
|
75
|
-
cancelEdit(ele.parentNode.parentNode);
|
|
76
|
-
} else if (ele.matches('.submit-edit-btn')) {
|
|
77
|
-
submitEdit(ele);
|
|
78
|
-
} else if (ele.matches('.delete-user-btn')) {
|
|
79
|
-
deleteUser(ele);
|
|
80
|
-
}
|
|
81
|
-
}, false);
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Add user
|
|
85
|
-
*/
|
|
86
|
-
function addUser() {
|
|
87
|
-
var nameInput = document.getElementById('name-input');
|
|
88
|
-
var emailInput = document.getElementById('email-input');
|
|
89
|
-
var data = {
|
|
90
|
-
user: {
|
|
91
|
-
name: nameInput.value,
|
|
92
|
-
email: emailInput.value,
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
Http
|
|
96
|
-
.post('/api/users/add', data)
|
|
97
|
-
.then(() => displayUsers());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Show edit view
|
|
102
|
-
*/
|
|
103
|
-
function showEditView(userEle) {
|
|
104
|
-
var normalView = userEle.getElementsByClassName('normal-view')[0];
|
|
105
|
-
var editView = userEle.getElementsByClassName('edit-view')[0];
|
|
106
|
-
normalView.style.display = 'none';
|
|
107
|
-
editView.style.display = 'block';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Cancel edit
|
|
112
|
-
*/
|
|
113
|
-
function cancelEdit(userEle) {
|
|
114
|
-
var normalView = userEle.getElementsByClassName('normal-view')[0];
|
|
115
|
-
var editView = userEle.getElementsByClassName('edit-view')[0];
|
|
116
|
-
normalView.style.display = 'block';
|
|
117
|
-
editView.style.display = 'none';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Submit edit
|
|
122
|
-
*/
|
|
123
|
-
function submitEdit(ele) {
|
|
124
|
-
var userEle = ele.parentNode.parentNode;
|
|
125
|
-
var nameInput = userEle.getElementsByClassName('name-edit-input')[0];
|
|
126
|
-
var emailInput = userEle.getElementsByClassName('email-edit-input')[0];
|
|
127
|
-
var id = ele.getAttribute('data-user-id');
|
|
128
|
-
var data = {
|
|
129
|
-
user: {
|
|
130
|
-
name: nameInput.value,
|
|
131
|
-
email: emailInput.value,
|
|
132
|
-
id: Number(id),
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
Http
|
|
136
|
-
.put('/api/users/update', data)
|
|
137
|
-
.then(() => displayUsers());
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Delete user
|
|
142
|
-
*/
|
|
143
|
-
function deleteUser(ele) {
|
|
144
|
-
var id = ele.getAttribute('data-user-id');
|
|
145
|
-
Http
|
|
146
|
-
.delete('/api/users/delete/' + id)
|
|
147
|
-
.then(() => displayUsers());
|
|
148
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
body #window-wrapper {
|
|
3
|
-
height: 350px;
|
|
4
|
-
width: 500px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
body #window-wrapper #chat-window {
|
|
8
|
-
height: 100%;
|
|
9
|
-
width: 100%;
|
|
10
|
-
border: 1px solid rgb(182, 182, 182);
|
|
11
|
-
border-radius: 4px;
|
|
12
|
-
overflow-y: scroll;
|
|
13
|
-
padding: 10px 10px 0px 10px;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
body #window-wrapper #chat-window .chat-msg {
|
|
17
|
-
padding-bottom: 5px;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
body #window-wrapper #chat-window .chat-msg .msg-name {
|
|
21
|
-
font-weight: bold;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
body #window-wrapper #chat-window .chat-msg .msg-timestamp {
|
|
25
|
-
font-weight: bold;
|
|
26
|
-
color: grey;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
body #window-wrapper #send-msg-wrapper {
|
|
30
|
-
padding-top: 20px;
|
|
31
|
-
display: flex;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
body #window-wrapper #send-msg-wrapper input {
|
|
35
|
-
width: 75%;
|
|
36
|
-
flex-grow: 1;
|
|
37
|
-
padding: 4px;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
body #window-wrapper #send-msg-wrapper #send-msg-btn {
|
|
41
|
-
margin-left: 10px;
|
|
42
|
-
font-size: 16px;
|
|
43
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
body .login-block {
|
|
3
|
-
display: inline-block;
|
|
4
|
-
margin-right: 2em;
|
|
5
|
-
vertical-align: top;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
body .login-block .login-header {
|
|
9
|
-
font-weight: bold;
|
|
10
|
-
margin-bottom: 1em;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
body .login-block .login-input {
|
|
14
|
-
margin-bottom: 1em;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
body .login-block .default-login-user {
|
|
18
|
-
margin-top: 1em;
|
|
19
|
-
color: #909090;
|
|
20
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
body .users-column {
|
|
3
|
-
display: inline-block;
|
|
4
|
-
margin-right: 2em;
|
|
5
|
-
vertical-align: top;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
body .users-column .column-header {
|
|
9
|
-
padding-bottom: 5px;
|
|
10
|
-
font-weight: 700;
|
|
11
|
-
font-size: 1.2em;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/* Add User Column */
|
|
16
|
-
|
|
17
|
-
body .add-user-col input {
|
|
18
|
-
margin-bottom: 10px;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
body .add-user-col #add-user-btn {
|
|
22
|
-
margin-top: 2px;
|
|
23
|
-
margin-bottom: 10px;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/* Users Display Column */
|
|
28
|
-
|
|
29
|
-
body .users-column .user-display-ele {
|
|
30
|
-
padding-bottom: 10px;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
body .users-column .user-display-ele button {
|
|
34
|
-
margin-top: 2px;
|
|
35
|
-
margin-bottom: 10px;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
body .users-column .user-display-ele .edit-view {
|
|
39
|
-
display: none;
|
|
40
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"users": [
|
|
3
|
-
{
|
|
4
|
-
"name": "Sean Maxwell",
|
|
5
|
-
"email": "sean.maxwell@gmail.com",
|
|
6
|
-
"pwdHash": "$2b$12$1mE2OI9hMS/rgH9Mi0s85OM2V5gzm7aF3gJIWH1y0S1MqVBueyjsy",
|
|
7
|
-
"role": 0,
|
|
8
|
-
"id": 906524522143
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"name": "Aaaaa aaaa",
|
|
12
|
-
"email": "aaaa@gmail.com",
|
|
13
|
-
"pwdHash": "$2b$12$1mE2OI9hMS/rgH9Mi0s85OM2V5gzm7aF3gJIWH1y0S1MqVBueyjsy",
|
|
14
|
-
"role": 0,
|
|
15
|
-
"id": 906524522143
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"name": "asdfasdfadsf",
|
|
19
|
-
"email": "sadfasdf",
|
|
20
|
-
"id": 319667476404
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"name": "eeeeee",
|
|
24
|
-
"email": "eeeeeeee",
|
|
25
|
-
"id": 654396130856
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"name": "asdf",
|
|
29
|
-
"email": "ccccccc",
|
|
30
|
-
"id": 134807566562
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"name": "asdf",
|
|
34
|
-
"email": "asdf",
|
|
35
|
-
"id": 496001336575
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
2
|
-
|
|
3
|
-
import jsonfile from 'jsonfile';
|
|
4
|
-
import { IUser } from '@models/user-model';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// **** Variables **** //
|
|
8
|
-
|
|
9
|
-
const dbFilePath = 'src/repos/database.json';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// **** Types **** //
|
|
13
|
-
|
|
14
|
-
interface IDb {
|
|
15
|
-
users: IUser[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// **** Functions **** //
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Fetch the json from the file.
|
|
23
|
-
*/
|
|
24
|
-
function openDb(): Promise<IDb> {
|
|
25
|
-
return jsonfile.readFile(dbFilePath);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Update the file.
|
|
30
|
-
*/
|
|
31
|
-
function saveDb(db: IDb): Promise<void> {
|
|
32
|
-
return jsonfile.writeFile(dbFilePath, db);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// **** Export default **** //
|
|
37
|
-
|
|
38
|
-
export default {
|
|
39
|
-
openDb,
|
|
40
|
-
saveDb,
|
|
41
|
-
} as const;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { IUser } from '@models/user-model';
|
|
2
|
-
import { getRandomInt } from '@shared/functions';
|
|
3
|
-
import orm from './mock-orm';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// **** Functions **** //
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get one user
|
|
10
|
-
*/
|
|
11
|
-
async function getOne(email: string): Promise<IUser | null> {
|
|
12
|
-
const db = await orm.openDb();
|
|
13
|
-
for (const user of db.users) {
|
|
14
|
-
if (user.email === email) {
|
|
15
|
-
return user;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* See if a user with the given id exists.
|
|
23
|
-
*/
|
|
24
|
-
async function persists(id: number): Promise<boolean> {
|
|
25
|
-
const db = await orm.openDb();
|
|
26
|
-
for (const user of db.users) {
|
|
27
|
-
if (user.id === id) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get all users.
|
|
36
|
-
*/
|
|
37
|
-
async function getAll(): Promise<IUser[]> {
|
|
38
|
-
const db = await orm.openDb();
|
|
39
|
-
return db.users;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Add one user.
|
|
44
|
-
*/
|
|
45
|
-
async function add(user: IUser): Promise<void> {
|
|
46
|
-
const db = await orm.openDb();
|
|
47
|
-
user.id = getRandomInt();
|
|
48
|
-
db.users.push(user);
|
|
49
|
-
return orm.saveDb(db);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Update a user
|
|
54
|
-
*/
|
|
55
|
-
async function update(user: IUser): Promise<void> {
|
|
56
|
-
const db = await orm.openDb();
|
|
57
|
-
for (let i = 0; i < db.users.length; i++) {
|
|
58
|
-
if (db.users[i].id === user.id) {
|
|
59
|
-
db.users[i] = user;
|
|
60
|
-
return orm.saveDb(db);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Delete one user
|
|
67
|
-
*/
|
|
68
|
-
async function _delete(id: number): Promise<void> {
|
|
69
|
-
const db = await orm.openDb();
|
|
70
|
-
for (let i = 0; i < db.users.length; i++) {
|
|
71
|
-
if (db.users[i].id === id) {
|
|
72
|
-
db.users.splice(i, 1);
|
|
73
|
-
return orm.saveDb(db);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// **** Export default **** //
|
|
80
|
-
|
|
81
|
-
export default {
|
|
82
|
-
getOne,
|
|
83
|
-
persists,
|
|
84
|
-
getAll,
|
|
85
|
-
add,
|
|
86
|
-
update,
|
|
87
|
-
delete: _delete,
|
|
88
|
-
} as const;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
import { authMw } from './middleware';
|
|
3
|
-
import authRouter from './auth-router';
|
|
4
|
-
import userRouter from './user-router';
|
|
5
|
-
import chatRouter from './chat-router';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// Init
|
|
9
|
-
const apiRouter = Router();
|
|
10
|
-
|
|
11
|
-
// Add api routes
|
|
12
|
-
apiRouter.use('/auth', authRouter);
|
|
13
|
-
apiRouter.use('/users', authMw, userRouter);
|
|
14
|
-
apiRouter.use('/chat', authMw, chatRouter);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// **** Export default **** //
|
|
18
|
-
|
|
19
|
-
export default apiRouter;
|