/
constants.js
90 lines (83 loc) · 2.29 KB
/
constants.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const HttpStatus = require("http-status-codes");
const SALT_ROUNDS = 10;
const ADMIN_ID = 1;
const TOKEN_EXPIRATION = 86400;
const DEFAULT_CHANGELOG_MESSAGE = "Another drop in the ocean of knowledge";
// TODO The stuff that follow are ENUMS on the database. Could put them elsewhere when there's more
const ROLES = {
ADMIN: "ADMIN",
USER: "USER"
};
const ARTICLE_HISTORY_TYPES = {
CREATE: "CREATE",
UPDATE: "UPDATE",
DELETE: "DELETE"
};
// TODO separate errors.js file
// TODO remove messages from here and let front end decide based on error code
const ERRORS = {
DUPLICATE_TOPIC: {
status: HttpStatus.CONFLICT,
code: "ER_DUP_ENTRY",
message: "This topic already exists. Please use another name"
},
DUPLICATE_ADMIN_USER: {
status: HttpStatus.CONFLICT,
code: "ER_DUP_ENTRY",
message: "There was an error creating the admin user. Chances are you're already set up"
},
DUPLICATE_USER: {
status: HttpStatus.CONFLICT,
code: "ER_DUP_ENTRY",
message: "This email is already in use. Please try another email"
},
CREDS_WRONG: {
status: HttpStatus.BAD_REQUEST,
code: "CREDS_WRONG",
message: "Email or Password is wrong"
},
INVALID_TOKEN: {
status: HttpStatus.UNAUTHORIZED,
code: "INVALID_TOKEN",
message: "Failed to authenticate token"
},
BAD_ARTICLE_CREATE: {
status: HttpStatus.BAD_REQUEST,
code: "BAD_ARTICLE_CREATE",
message: "title, topicId and content are required"
},
BAD_ARTICLE_UPDATE: {
status: HttpStatus.BAD_REQUEST,
code: "BAD_ARTICLE_UPDATEE",
message: "title, topicId, change_log and content are required"
},
NO_ACCESS: {
status: HttpStatus.FORBIDDEN,
code: "NO_ACCESS",
message: "You are not authorized to perform this action"
},
NOT_FOUND: {
status: HttpStatus.NOT_FOUND,
code: "NOT_FOUND",
message: "Resource was not found"
},
DELETE_DEFAULT_TOPIC: {
status: HttpStatus.METHOD_NOT_ALLOWED,
code: "DELETE_DEFAULT_TOPIC",
message: "Can not delete default topic!"
},
DELETE_DEFAULT_ADMIN: {
status: HttpStatus.METHOD_NOT_ALLOWED,
code: "DELETE_DEFAULT_ADMIN",
message: "Can not delete admin user!"
}
};
module.exports = {
SALT_ROUNDS,
ADMIN_ID,
TOKEN_EXPIRATION,
DEFAULT_CHANGELOG_MESSAGE,
ROLES,
ARTICLE_HISTORY_TYPES,
ERRORS
};