bmd-extension 1.6.3
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/.vscode/launch.json +14 -0
- package/.vscode/settings.json +1 -0
- package/CHANGELOG.md +9 -0
- package/DEPLOY.md +4 -0
- package/README.md +17 -0
- package/README_PRIVATE.md +1 -0
- package/build.sh +5 -0
- package/logo.png +0 -0
- package/media/dark/add.svg +40 -0
- package/media/dark/block.svg +1 -0
- package/media/dark/checklist-1.svg +1 -0
- package/media/dark/checklist.svg +1 -0
- package/media/dark/control.svg +1 -0
- package/media/dark/create.svg +1 -0
- package/media/dark/delete-1.svg +1 -0
- package/media/dark/delete.svg +1 -0
- package/media/dark/deploy-1.svg +2 -0
- package/media/dark/deploy.svg +2 -0
- package/media/dark/documents.svg +66 -0
- package/media/dark/earth.svg +68 -0
- package/media/dark/exe.svg +15 -0
- package/media/dark/export.svg +1 -0
- package/media/dark/function.svg +1 -0
- package/media/dark/game-controller.svg +77 -0
- package/media/dark/get.svg +1 -0
- package/media/dark/id-card.svg +59 -0
- package/media/dark/identity.svg +81 -0
- package/media/dark/import.svg +1 -0
- package/media/dark/information.svg +1 -0
- package/media/dark/interface.svg +1 -0
- package/media/dark/layout.svg +41 -0
- package/media/dark/leaf.svg +54 -0
- package/media/dark/list.svg +13 -0
- package/media/dark/logo.svg +249 -0
- package/media/dark/mockup.svg +1 -0
- package/media/dark/needle.svg +1 -0
- package/media/dark/pass.svg +46 -0
- package/media/dark/plus.svg +1 -0
- package/media/dark/post.svg +1 -0
- package/media/dark/quit.svg +1 -0
- package/media/dark/rocket.svg +28 -0
- package/media/dark/service.svg +1 -0
- package/media/dark/settings.svg +98 -0
- package/media/dark/social.svg +1 -0
- package/media/dark/spaceship-1.svg +1 -0
- package/media/dark/spaceship-2.svg +1 -0
- package/media/dark/spaceship.svg +1 -0
- package/media/dark/support.svg +88 -0
- package/media/dark/transfer.svg +1 -0
- package/media/dark/transform.svg +92 -0
- package/media/dark/update.svg +45 -0
- package/media/dark/upload-1.svg +1 -0
- package/media/dark/upload.svg +41 -0
- package/media/dark/vaccine.svg +1 -0
- package/media/dark/vr-gaming.svg +1 -0
- package/media/light/add.svg +40 -0
- package/media/light/block.svg +1 -0
- package/media/light/checklist-1.svg +1 -0
- package/media/light/checklist.svg +1 -0
- package/media/light/control.svg +1 -0
- package/media/light/create.svg +1 -0
- package/media/light/delete-1.svg +1 -0
- package/media/light/delete.svg +1 -0
- package/media/light/deploy-1.svg +2 -0
- package/media/light/deploy.svg +2 -0
- package/media/light/documents.svg +66 -0
- package/media/light/earth.svg +68 -0
- package/media/light/exe.svg +15 -0
- package/media/light/export.svg +1 -0
- package/media/light/function.svg +1 -0
- package/media/light/game-controller.svg +77 -0
- package/media/light/get.svg +1 -0
- package/media/light/id-card.svg +59 -0
- package/media/light/identity.svg +81 -0
- package/media/light/import.svg +1 -0
- package/media/light/information.svg +1 -0
- package/media/light/interface.svg +1 -0
- package/media/light/layout.svg +41 -0
- package/media/light/leaf.svg +54 -0
- package/media/light/list.svg +13 -0
- package/media/light/logo.svg +249 -0
- package/media/light/mockup.svg +1 -0
- package/media/light/needle.svg +1 -0
- package/media/light/pass.svg +46 -0
- package/media/light/plus.svg +1 -0
- package/media/light/post.svg +1 -0
- package/media/light/quit.svg +1 -0
- package/media/light/rocket.svg +28 -0
- package/media/light/service.svg +1 -0
- package/media/light/settings.svg +98 -0
- package/media/light/social.svg +1 -0
- package/media/light/spaceship-1.svg +1 -0
- package/media/light/spaceship-2.svg +1 -0
- package/media/light/spaceship.svg +1 -0
- package/media/light/support.svg +88 -0
- package/media/light/transfer.svg +1 -0
- package/media/light/transform.svg +92 -0
- package/media/light/update.svg +45 -0
- package/media/light/upload-1.svg +1 -0
- package/media/light/upload.svg +41 -0
- package/media/light/vaccine.svg +1 -0
- package/media/light/vr-gaming.svg +1 -0
- package/package-lock.json +6430 -0
- package/package.json +540 -0
- package/snippets-tsr.json +512 -0
- package/snippets.json +761 -0
- package/src/API.ts +14 -0
- package/src/FsProvider.ts +105 -0
- package/src/Request.ts +24 -0
- package/src/assets/api/api.txt +27 -0
- package/src/assets/configuration/AdminConfigurationController.ts.txt +72 -0
- package/src/assets/configuration/Configuration.ts.txt +37 -0
- package/src/assets/configuration/ConfigurationService.ts.txt +26 -0
- package/src/assets/contentDefine/AdminContentDefineController.ts.txt +91 -0
- package/src/assets/contentDefine/ContentDefine.ts.txt +45 -0
- package/src/assets/contentDefine/ContentDefineService.ts.txt +19 -0
- package/src/assets/contentDefine/CustomerContentDefineController.ts.txt +34 -0
- package/src/assets/controller/controller.txt +46 -0
- package/src/assets/controller/controllerResource.txt +103 -0
- package/src/assets/entity/entity.txt +22 -0
- package/src/assets/entity-request/entity-request.txt +18 -0
- package/src/assets/init/.env.example.txt +37 -0
- package/src/assets/init/.env.production.txt +37 -0
- package/src/assets/init/.gitignore.txt +8 -0
- package/src/assets/init/config.ts.txt +55 -0
- package/src/assets/init/deploy.sh.txt +46 -0
- package/src/assets/init/package-lock.json.txt +4184 -0
- package/src/assets/init/package.json.txt +79 -0
- package/src/assets/init/src/Server.ts.txt +167 -0
- package/src/assets/init/src/controllers/admin/AuthController.ts.txt +96 -0
- package/src/assets/init/src/controllers/admin/CustomerController.ts.txt +107 -0
- package/src/assets/init/src/controllers/admin/RoleController.ts.txt +143 -0
- package/src/assets/init/src/controllers/admin/StaffController.ts.txt +192 -0
- package/src/assets/init/src/controllers/customer/AuthController.ts.txt +170 -0
- package/src/assets/init/src/controllers/customer/CustomerController.ts.txt +32 -0
- package/src/assets/init/src/core/entity/CoreEntity.ts.txt +70 -0
- package/src/assets/init/src/core/services/CoreService.ts.txt +21 -0
- package/src/assets/init/src/entity/Customer.ts.txt +68 -0
- package/src/assets/init/src/entity/Permission.ts.txt +29 -0
- package/src/assets/init/src/entity/Role.ts.txt +36 -0
- package/src/assets/init/src/entity/Staff.ts.txt +54 -0
- package/src/assets/init/src/entity-request/CustomerInsert.ts.txt +42 -0
- package/src/assets/init/src/entity-request/CustomerUpdate.ts.txt +40 -0
- package/src/assets/init/src/entity-request/PermissionImport.ts.txt +12 -0
- package/src/assets/init/src/entity-request/StaffUpdate.ts.txt +33 -0
- package/src/assets/init/src/index.ts.txt +13 -0
- package/src/assets/init/src/middleware/auth/Verification.ts.txt +16 -0
- package/src/assets/init/src/middleware/auth/VerificationJWT.ts.txt +16 -0
- package/src/assets/init/src/middleware/auth/strategy/AuthStrategy.ts.txt +5 -0
- package/src/assets/init/src/middleware/auth/strategy/JWT.ts.txt +147 -0
- package/src/assets/init/src/middleware/error/handleError.ts.txt +22 -0
- package/src/assets/init/src/middleware/error/handleNotFound.ts.txt +7 -0
- package/src/assets/init/src/middleware/response/CustomSendResponse.ts.txt +35 -0
- package/src/assets/init/src/middleware/response/responseAPI.ts.txt +76 -0
- package/src/assets/init/src/middleware/validator/Validator.ts.txt +103 -0
- package/src/assets/init/src/services/CustomerService.ts.txt +79 -0
- package/src/assets/init/src/services/InitService.ts.txt +11 -0
- package/src/assets/init/src/services/MailService.ts.txt +271 -0
- package/src/assets/init/src/services/RoleService.ts.txt +66 -0
- package/src/assets/init/src/services/StaffService.ts.txt +104 -0
- package/src/assets/init/src/ssl/certificate-ca.crt +0 -0
- package/src/assets/init/src/ssl/certificate.crt +0 -0
- package/src/assets/init/src/ssl/private.key +0 -0
- package/src/assets/init/src/types/express.d.ts.txt +97 -0
- package/src/assets/init/src/util/expo.ts.txt +53 -0
- package/src/assets/init/src/util/helper.ts.txt +321 -0
- package/src/assets/init/src/util/language.ts.txt +8 -0
- package/src/assets/init/src/util/logger.ts.txt +47 -0
- package/src/assets/init/src/util/mailer.ts.txt +32 -0
- package/src/assets/init/src/util/password.ts.txt +13 -0
- package/src/assets/init/tsconfig.json.txt +26 -0
- package/src/assets/service/service.txt +34 -0
- package/src/constant.ts +83 -0
- package/src/extension.ts +459 -0
- package/src/provider/codeAction/controller/addPathParams.ts +65 -0
- package/src/provider/codeAction/controller/addTokenParam.ts +43 -0
- package/src/provider/codeAction/controller/addValidation.ts +47 -0
- package/src/provider/codeAction/controller/codeAction.ts +34 -0
- package/src/provider/codeAction/controller/util.ts +48 -0
- package/src/provider/codeAction/entity/codeAction.ts +48 -0
- package/src/provider/codeAction/entity/handleBuilder.ts +87 -0
- package/src/provider/codeAction/entity/handleFunction.ts +487 -0
- package/src/provider/codeAction/entity/handleProperty.ts +32 -0
- package/src/provider/codeAction/entity/handleRelation.ts +72 -0
- package/src/provider/codeAction/entity/helper.ts +132 -0
- package/src/provider/codeAction/entity-request/codeAction.ts +178 -0
- package/src/provider/codeAction/enum/codeAction.ts +95 -0
- package/src/provider/codeAction/service/codeAction.ts +232 -0
- package/src/provider/completion/CompletionProvider.ts +108 -0
- package/src/provider/errorChecking/checkHeaderToken.ts +60 -0
- package/src/provider/errorChecking/checkPathParam.ts +64 -0
- package/src/provider/errorChecking/checkRequired.ts +56 -0
- package/src/provider/errorChecking/errorChecking.ts +35 -0
- package/src/provider/errorChecking/util.ts +56 -0
- package/src/provider/treeDataProvider/Dependency.ts +26 -0
- package/src/provider/treeDataProvider/TreeProviderCommand.ts +60 -0
- package/src/provider/treeDataProvider/TreeProviderProject.ts +65 -0
- package/src/provider/treeDataProvider/api/createApi.ts +106 -0
- package/src/provider/treeDataProvider/controller/command/createController.ts +99 -0
- package/src/provider/treeDataProvider/controller/command/handleMethod.ts +363 -0
- package/src/provider/treeDataProvider/controller/treeData.ts +81 -0
- package/src/provider/treeDataProvider/deploy/command/handleDeploy.ts +70 -0
- package/src/provider/treeDataProvider/deploy/treeData.ts +21 -0
- package/src/provider/treeDataProvider/entity/command/addProperty.ts +144 -0
- package/src/provider/treeDataProvider/entity/command/addRelation.ts +125 -0
- package/src/provider/treeDataProvider/entity/command/createEntity.ts +53 -0
- package/src/provider/treeDataProvider/entity/command/createEntityRequest.ts +65 -0
- package/src/provider/treeDataProvider/entity/command/exportInterface.ts +130 -0
- package/src/provider/treeDataProvider/entity/treeData.ts +49 -0
- package/src/provider/treeDataProvider/module/command/configuration.ts +34 -0
- package/src/provider/treeDataProvider/module/command/contentDefine.ts +36 -0
- package/src/provider/treeDataProvider/module/command/initProject.ts +155 -0
- package/src/provider/treeDataProvider/module/treeData.ts +28 -0
- package/src/provider/treeDataProvider/project/command/addEnum.ts +0 -0
- package/src/provider/treeDataProvider/project/command/addProjectName.ts +23 -0
- package/src/provider/treeDataProvider/project/command/getProjectDetails.ts +284 -0
- package/src/provider/treeDataProvider/project/treeData.ts +28 -0
- package/src/provider/treeDataProvider/service/command/createService.ts +70 -0
- package/src/provider/treeDataProvider/service/command/handleConstructor.ts +134 -0
- package/src/provider/treeDataProvider/service/treeData.ts +25 -0
- package/src/types/project.d.ts +7 -0
- package/src/util.ts +145 -0
- package/src/utils/Password.ts +19 -0
- package/tsconfig.json +18 -0
- package/tslint.json +15 -0
- package/vsc-extension-quickstart.md +42 -0
@@ -0,0 +1,321 @@
|
|
1
|
+
import moment from 'moment';
|
2
|
+
import 'moment/locale/vi'
|
3
|
+
import config from '../../config';
|
4
|
+
import md5 from 'md5';
|
5
|
+
moment.locale('vi')
|
6
|
+
const SECONDS_IN_A_DAY = 60 * 60 * 24
|
7
|
+
/**
|
8
|
+
* ==============================================================================
|
9
|
+
* ====================================STRING====================================
|
10
|
+
* ==============================================================================
|
11
|
+
*/
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Capitalizes the first letter of a string.
|
15
|
+
* Example: capitalize('fooBar'); // 'FooBar'
|
16
|
+
* capitalize('fooBar', true); // 'Foobar'
|
17
|
+
*/
|
18
|
+
export const capitalize = ([first, ...rest]: string, lowerRest = false) =>
|
19
|
+
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
|
20
|
+
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Capitalizes the first letter of a string.
|
24
|
+
* Example: capitalize('fooBar'); // 'FooBar'
|
25
|
+
* capitalize('fooBar', true); // 'Foobar'
|
26
|
+
*/
|
27
|
+
export const isNumberPhoneVN = (phone: string) => {
|
28
|
+
const regex = /((03|04|05|07|08|09)+([0-9]{8})\b)/g
|
29
|
+
return regex.test(phone)
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Capitalizes the first letter of every word in a string.
|
35
|
+
* Example: capitalizeEveryWord('hello world!'); // 'Hello World!'
|
36
|
+
*/
|
37
|
+
export const capitalizeEveryWord = (str: string) => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Converts a string to camelcase.
|
41
|
+
* Example: toCamelCase('some_database_field_name'); // 'someDatabaseFieldName'
|
42
|
+
* toCamelCase('Some label that needs to be camelized'); // 'someLabelThatNeedsToBeCamelized'
|
43
|
+
* toCamelCase('some-javascript-property'); // 'someJavascriptProperty'
|
44
|
+
* toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'); // 'someMixedStringWithSpacesUnderscoresAndHyphens
|
45
|
+
*/
|
46
|
+
export const toCamelCase = (str: string) => {
|
47
|
+
let s =
|
48
|
+
str &&
|
49
|
+
str
|
50
|
+
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
51
|
+
.map(x => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
|
52
|
+
.join('');
|
53
|
+
return s.slice(0, 1).toLowerCase() + s.slice(1);
|
54
|
+
};
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Replaces all but the last num of characters with the specified mask character.
|
58
|
+
* Example: mask(1234567890); // '******7890'
|
59
|
+
* mask(1234567890, 3); // '*******890'
|
60
|
+
* mask(1234567890, -4, '$'); // '$$$$567890'
|
61
|
+
*/
|
62
|
+
export const mask = (cc: string, num = 4, mask = '*') => `${cc}`.slice(-num).padStart(`${cc}`.length, mask);
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Format number to VND.
|
66
|
+
* Example: formatVND(10000); // '10.000'
|
67
|
+
*/
|
68
|
+
export function formatVND(num: number) {
|
69
|
+
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.')
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Format number to VND.
|
74
|
+
* Example: randomString(6); // 'bmakcn'
|
75
|
+
* Example: randomString(7); // 'kjskcnd'
|
76
|
+
*/
|
77
|
+
export const randomString = (length: number) => Math.random().toString(36).substring(length);
|
78
|
+
|
79
|
+
export function convertCityToSlug(str: string) {
|
80
|
+
str = str
|
81
|
+
.replace(/city/g, "")
|
82
|
+
.replace("Thành phố", "")
|
83
|
+
.trim()
|
84
|
+
.toLowerCase()
|
85
|
+
console.log('str:', str)
|
86
|
+
return toSlug(str)
|
87
|
+
}
|
88
|
+
|
89
|
+
export function toSlug(str: string, separator: string = "") {
|
90
|
+
str = str
|
91
|
+
.toLowerCase()
|
92
|
+
.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a")
|
93
|
+
.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e")
|
94
|
+
.replace(/ì|í|ị|ỉ|ĩ/g, "i")
|
95
|
+
.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o")
|
96
|
+
.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u")
|
97
|
+
.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y")
|
98
|
+
.replace(/đ/g, "d")
|
99
|
+
.replace(/\s+/g, "-")
|
100
|
+
.replace(/[^A-Za-z0-9_-]/g, "")
|
101
|
+
.replace(/-+/g, "-");
|
102
|
+
if (separator) {
|
103
|
+
return str.replace(/-/g, separator);
|
104
|
+
}
|
105
|
+
return str;
|
106
|
+
}
|
107
|
+
|
108
|
+
export const randomCode = (length: number) => md5(`${moment().valueOf()}`).substring(0, length).toUpperCase()
|
109
|
+
|
110
|
+
/**
|
111
|
+
* ==============================================================================
|
112
|
+
* ====================================OBJECT====================================
|
113
|
+
* ==============================================================================
|
114
|
+
*/
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Check if object if empty
|
118
|
+
* Example: isEmptyObject({}) // true
|
119
|
+
* isEmptyObject({a: 1}) // false
|
120
|
+
*/
|
121
|
+
export function isEmptyObject(object: Object): boolean {
|
122
|
+
if (typeof object !== "object") return false
|
123
|
+
if (!object) return false
|
124
|
+
return !!Object.keys(object).length
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Picks the key-value pairs corresponding to the given keys from an object.
|
129
|
+
* Example: pick({ a: 1, b: '2', c: 3 }, ['a', 'c']); // { 'a': 1, 'c': 3 }
|
130
|
+
*/
|
131
|
+
const pick = (obj: any, arr: string[]) =>
|
132
|
+
arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
|
133
|
+
|
134
|
+
/**
|
135
|
+
* ==============================================================================
|
136
|
+
* ====================================TIME====================================
|
137
|
+
* ==============================================================================
|
138
|
+
*/
|
139
|
+
export function convertHHMMToNumber(text: string): { minute: number, hour: number } {
|
140
|
+
const hour = 0
|
141
|
+
const minute = 0
|
142
|
+
|
143
|
+
if (!text || !text.includes(':')) {
|
144
|
+
return { hour: 0, minute: 0 }
|
145
|
+
}
|
146
|
+
|
147
|
+
const [hourText, minuteText] = text.split(':')
|
148
|
+
return { hour: +hourText, minute: +minuteText }
|
149
|
+
}
|
150
|
+
|
151
|
+
export function getCurrentDateMMYY(): string {
|
152
|
+
return moment().format('MMYY')
|
153
|
+
}
|
154
|
+
|
155
|
+
export function getCurrentDateDDMMYY(): string {
|
156
|
+
return moment().format('DDMMYY')
|
157
|
+
}
|
158
|
+
|
159
|
+
export function getCurrentTimeInt(): number {
|
160
|
+
return +(moment().valueOf() / 1000).toFixed()
|
161
|
+
}
|
162
|
+
|
163
|
+
export function getMonthInterval(date: Date) {
|
164
|
+
let start = moment(date).startOf("months")
|
165
|
+
let end = start.clone().add(1, "months")
|
166
|
+
return {
|
167
|
+
start: start.valueOf() / 1000,
|
168
|
+
end: end.valueOf() / 1000
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
export function convertFullDateToInt(date: Date): { start: number, end: number } {
|
173
|
+
let time = +(date.getTime() / 1000).toFixed()
|
174
|
+
let start = Math.round(time / SECONDS_IN_A_DAY) * SECONDS_IN_A_DAY
|
175
|
+
return {
|
176
|
+
start,
|
177
|
+
end: start + SECONDS_IN_A_DAY
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
export function convertIntToDDMMYY(int: number): string {
|
182
|
+
return moment(int * 1000).format('DD/MM/YYYY')
|
183
|
+
}
|
184
|
+
|
185
|
+
export function convertIntToddddDDMMYY(int: number): string {
|
186
|
+
return moment(int * 1000).locale('vi').format('dddd, DD/MM/YYYY')
|
187
|
+
}
|
188
|
+
|
189
|
+
export function convertDateToInt(date: Date): number {
|
190
|
+
let time = +(date.getTime() / 1000).toFixed()
|
191
|
+
return time * SECONDS_IN_A_DAY / SECONDS_IN_A_DAY
|
192
|
+
}
|
193
|
+
|
194
|
+
export function getMomentByDate(date: Date = new Date()): moment.Moment {
|
195
|
+
return moment(date)
|
196
|
+
}
|
197
|
+
|
198
|
+
export function getMomentToday(): moment.Moment {
|
199
|
+
return moment().startOf("day")
|
200
|
+
}
|
201
|
+
|
202
|
+
export function getTodayInterval(): { start: number, end: number } {
|
203
|
+
let start = moment().startOf("day")
|
204
|
+
let end = start.clone().add(1, "days")
|
205
|
+
return {
|
206
|
+
start: start.valueOf() / 1000,
|
207
|
+
end: end.valueOf() / 1000
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
export function getThisWeekInterval(): { start: number, end: number } {
|
212
|
+
let start = moment().startOf("isoWeeks")
|
213
|
+
let end = start.clone().add(1, "weeks")
|
214
|
+
return {
|
215
|
+
start: start.valueOf() / 1000,
|
216
|
+
end: end.valueOf() / 1000
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
export function getDateInterval(date: any): { start: number, end: number } {
|
221
|
+
let start = moment(date).startOf("day")
|
222
|
+
let end = start.clone().add(1, "days")
|
223
|
+
return {
|
224
|
+
start: start.valueOf() / 1000,
|
225
|
+
end: end.valueOf() / 1000
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
export function getThisMonthInterval(): { start: number, end: number } {
|
230
|
+
let start = moment().startOf("months")
|
231
|
+
let end = start.clone().add(1, "months")
|
232
|
+
return {
|
233
|
+
start: start.valueOf() / 1000,
|
234
|
+
end: end.valueOf() / 1000
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
export function getMomentBySecond(second: number): moment.Moment {
|
239
|
+
return moment(second * 1000)
|
240
|
+
}
|
241
|
+
|
242
|
+
export function getMomentByMiliSecond(miliSecond: number): moment.Moment {
|
243
|
+
return moment(miliSecond)
|
244
|
+
}
|
245
|
+
|
246
|
+
export function getWeekOfMonth(date: moment.Moment) {
|
247
|
+
return date.isoWeek() - moment(date).startOf('month').isoWeek() + 1;
|
248
|
+
}
|
249
|
+
|
250
|
+
export function getFromToDate(from: Date = null, to: Date = null) {
|
251
|
+
let { start, end } = getThisMonthInterval()
|
252
|
+
if (from && to) {
|
253
|
+
const dateFrom = convertFullDateToInt(from)
|
254
|
+
start = dateFrom.start
|
255
|
+
const dateTo = convertFullDateToInt(to)
|
256
|
+
end = dateTo.end
|
257
|
+
}
|
258
|
+
return { start, end }
|
259
|
+
}
|
260
|
+
|
261
|
+
/**
|
262
|
+
* ==============================================================================
|
263
|
+
* ====================================NUMBER====================================
|
264
|
+
* ==============================================================================
|
265
|
+
*/
|
266
|
+
|
267
|
+
/**
|
268
|
+
* Getting a random integer between two values
|
269
|
+
* Example: getRandomIntInclusive(0, 10); // 9
|
270
|
+
*/
|
271
|
+
export function getRandomIntInclusive(min: number, max: number) {
|
272
|
+
min = Math.ceil(min);
|
273
|
+
max = Math.floor(max);
|
274
|
+
return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive
|
275
|
+
}
|
276
|
+
|
277
|
+
export function roundToThousand(value: number) {
|
278
|
+
return (value / 1000 * 1000)
|
279
|
+
}
|
280
|
+
|
281
|
+
/**
|
282
|
+
* ==============================================================================
|
283
|
+
* ====================================UTILITY====================================
|
284
|
+
* ==============================================================================
|
285
|
+
*/
|
286
|
+
|
287
|
+
/**
|
288
|
+
* Use to add prefix of table in db
|
289
|
+
* @param table table name in db
|
290
|
+
*/
|
291
|
+
export function addPrefix(table: string) {
|
292
|
+
const prefix = config.PREFIX_TABLE || ""
|
293
|
+
return prefix + table
|
294
|
+
}
|
295
|
+
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Pads the current string with 0
|
299
|
+
* Example: leftPad(10, 6); // 000010
|
300
|
+
*/
|
301
|
+
export function leftPad(number: number, maxLength: number) {
|
302
|
+
return `${number}`.padStart(maxLength, "0")
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
/**
|
307
|
+
* Logging follow format, easy to see
|
308
|
+
* Example: logSection('production mode');
|
309
|
+
*/
|
310
|
+
export function logSection(text: string) {
|
311
|
+
text = text.toUpperCase()
|
312
|
+
console.log('..........................................................................................');
|
313
|
+
console.log(`......................................${text}......................................`);
|
314
|
+
console.log('..........................................................................................');
|
315
|
+
}
|
316
|
+
|
317
|
+
export function sleep(ms: number) {
|
318
|
+
return new Promise((resolve) => {
|
319
|
+
setTimeout(resolve, ms);
|
320
|
+
});
|
321
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export const MESSAGE_VALIDATOR_VI = {
|
2
|
+
'any.required': () => ' không được để trống.',
|
3
|
+
'number.base': () => ' phải là số.',
|
4
|
+
'string.min': (min: number) => ` phải ít nhất ${min} kí tự.`,
|
5
|
+
'number.min': (min: number) => ` phải ít nhất là ${min}.`,
|
6
|
+
'string.max': (max: number) => ` phải nhỏ hơn hoặc bằng ${max} kí tự.`,
|
7
|
+
'number.max': (max: number) => ` phải nhỏ hơn hoặc bằng ${max}.`,
|
8
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { createLogger, format, transports } from 'winston'
|
2
|
+
import moment from 'moment';
|
3
|
+
import fs from 'fs';
|
4
|
+
import CONFIG from '../../config';
|
5
|
+
|
6
|
+
const { combine, timestamp, label, printf } = format;
|
7
|
+
const timestampFormat = () => moment().format('YYYY-MM-DD hh:mm:ss').trim();
|
8
|
+
const loggerFormat = printf(({ level, message, label, timestamp }) => {
|
9
|
+
return `${timestampFormat()} [${label}] ${level.toUpperCase()}: ${message}`;
|
10
|
+
});
|
11
|
+
|
12
|
+
function dailyRotateFileTransport(type: string) {
|
13
|
+
const logPath = `${CONFIG.LOG_DIR}/${type}`
|
14
|
+
|
15
|
+
if (!fs.existsSync(logPath)) {
|
16
|
+
fs.mkdirSync(logPath);
|
17
|
+
}
|
18
|
+
|
19
|
+
return new transports.File({
|
20
|
+
filename: `${logPath}/log-${moment().format('YYYY-MM-DD')}.log`,
|
21
|
+
});
|
22
|
+
}
|
23
|
+
|
24
|
+
function logger(type: string) {
|
25
|
+
return createLogger({
|
26
|
+
level: 'info',
|
27
|
+
format: combine(
|
28
|
+
label({ label: `${CONFIG.APPLICATION_NAME}` }),
|
29
|
+
timestamp(),
|
30
|
+
loggerFormat
|
31
|
+
),
|
32
|
+
transports: [
|
33
|
+
dailyRotateFileTransport(type),
|
34
|
+
new transports.Console({
|
35
|
+
silent: true,
|
36
|
+
format: format.combine(
|
37
|
+
format.colorize(),
|
38
|
+
format.printf(
|
39
|
+
info => `${timestampFormat()} ${info.level}: ${info.message}`
|
40
|
+
)
|
41
|
+
)
|
42
|
+
})
|
43
|
+
],
|
44
|
+
})
|
45
|
+
}
|
46
|
+
|
47
|
+
export default logger
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import nodemailer from 'nodemailer'
|
2
|
+
import config from '../../config';
|
3
|
+
import logger from './logger';
|
4
|
+
|
5
|
+
var transporter = nodemailer.createTransport({
|
6
|
+
service: 'gmail',
|
7
|
+
secure: false,
|
8
|
+
requireTLS: true,
|
9
|
+
auth: {
|
10
|
+
user: config.MAIL_USER,
|
11
|
+
pass: config.MAIL_PASS
|
12
|
+
}
|
13
|
+
})
|
14
|
+
|
15
|
+
export class Mailer {
|
16
|
+
static async sendMail(to: string, subject: string, html: string) {
|
17
|
+
try {
|
18
|
+
let info = await transporter.sendMail({
|
19
|
+
from: config.MAIL_USER,
|
20
|
+
to,
|
21
|
+
subject,
|
22
|
+
html
|
23
|
+
});
|
24
|
+
console.log('info:', info)
|
25
|
+
logger('info').info('Sent mail info: ', info)
|
26
|
+
} catch (error) {
|
27
|
+
console.log('error:', error)
|
28
|
+
logger('error').error('Sent mail error: ', error)
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import bcrypt from 'bcrypt';
|
2
|
+
|
3
|
+
const SALT_ROUNDS = 10;
|
4
|
+
|
5
|
+
export class Password {
|
6
|
+
static hash(password: string): Promise<string> {
|
7
|
+
return bcrypt.hash(password, SALT_ROUNDS)
|
8
|
+
}
|
9
|
+
|
10
|
+
static validate(password: string, hash: string): Promise<boolean> {
|
11
|
+
return bcrypt.compare(password, hash)
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"module": "commonjs",
|
4
|
+
"esModuleInterop": true,
|
5
|
+
"target": "es6",
|
6
|
+
"moduleResolution": "node",
|
7
|
+
"emitDecoratorMetadata": true,
|
8
|
+
"experimentalDecorators": true,
|
9
|
+
"outDir": "dist",
|
10
|
+
"sourceMap": true,
|
11
|
+
"lib": [
|
12
|
+
"es2015",
|
13
|
+
"es2017"
|
14
|
+
],
|
15
|
+
"types": [
|
16
|
+
"reflect-metadata"
|
17
|
+
],
|
18
|
+
"declaration": false
|
19
|
+
},
|
20
|
+
"include": [
|
21
|
+
"src/**/*"
|
22
|
+
],
|
23
|
+
"exclude": [
|
24
|
+
"node_modules"
|
25
|
+
]
|
26
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Service } from "@tsed/common";
|
3
|
+
|
4
|
+
|
5
|
+
// IMPORT CUSTOM
|
6
|
+
import { {{classify}} } from "../entity/{{classify}}";
|
7
|
+
|
8
|
+
interface {{classify}}Query {
|
9
|
+
page: number;
|
10
|
+
limit: number
|
11
|
+
search?: string
|
12
|
+
}
|
13
|
+
|
14
|
+
@Service()
|
15
|
+
export class {{classify}}Service {
|
16
|
+
|
17
|
+
async getManyAndCount({
|
18
|
+
page,
|
19
|
+
limit,
|
20
|
+
search = '',
|
21
|
+
}: {{classify}}Query) {
|
22
|
+
let where = `{{camel}}.name LIKE :search AND {{camel}}.isDeleted = false`;
|
23
|
+
|
24
|
+
const [{{camel}}s, total] = await {{classify}}.createQueryBuilder('{{camel}}')
|
25
|
+
.where(where, { search: `%${search}%` })
|
26
|
+
.skip((page - 1) * limit)
|
27
|
+
.take(limit)
|
28
|
+
.orderBy('{{camel}}.id', 'DESC')
|
29
|
+
.getManyAndCount()
|
30
|
+
|
31
|
+
return { {{camel}}s, total }
|
32
|
+
}
|
33
|
+
|
34
|
+
} //END FILE
|
package/src/constant.ts
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
export enum ControllerAction {
|
2
|
+
Get = 'bmdextension.get',
|
3
|
+
Post = 'bmdextension.post',
|
4
|
+
GetListPagination = 'bmdextension.getListPagination',
|
5
|
+
GetListAll = 'bmdextension.getListAll',
|
6
|
+
CreateItem = 'bmdextension.createItem',
|
7
|
+
UpdateItem = 'bmdextension.updateItem',
|
8
|
+
CreateItemEntityRequest = 'bmdextension.createItemEntityRequest',
|
9
|
+
DeleteItemByRemove = 'bmdextension.deleteItemByRemove',
|
10
|
+
DeleteItemByBlock = 'bmdextension.deleteItemByBlock',
|
11
|
+
Upload = 'bmdextension.upload',
|
12
|
+
UploadResize = 'bmdextension.uploadResize',
|
13
|
+
AddPathParams = 'BMD: Add @PathParams',
|
14
|
+
AddTokenParam = 'BMD: Add token param',
|
15
|
+
AddValidation = 'BMD: Add validate'
|
16
|
+
}
|
17
|
+
|
18
|
+
export enum EntityAction {
|
19
|
+
AddProperty = 'bmdextension.addProperty',
|
20
|
+
OneToMany = 'bmdextension.oneToMany',
|
21
|
+
ManyToOne = 'bmdextension.manyToOne',
|
22
|
+
ManyToMany = 'bmdextension.manyToMany',
|
23
|
+
OneToOne = 'bmdextension.oneToOne',
|
24
|
+
OpenAndScrollToRelation = 'BMD: Open and scroll to Relations',
|
25
|
+
ExportInterface = 'bmdextension.exportInterface',
|
26
|
+
AddRelation = 'BMD: Add relation',
|
27
|
+
FindOneOrThrowID = 'BMD: Find one or throw ID',
|
28
|
+
CreateQueryBuilderPagination = 'BMD: Create query builder pagination',
|
29
|
+
CreateQueryBuilderFindAll = 'BMD: Create query builder find all',
|
30
|
+
CreateQueryBuilderFindOne = 'BMD: Create query builder find one',
|
31
|
+
AddBuilderRelation = 'BMD: Add relation builder',
|
32
|
+
AddPropertyToQuery = 'BMD: Add properties to query string',
|
33
|
+
}
|
34
|
+
|
35
|
+
export enum BMDCommand {
|
36
|
+
Init = 'bmdextension.init',
|
37
|
+
CreateControllerResource = 'bmdextension.createControllerResource',
|
38
|
+
CreateController = 'bmdextension.createController',
|
39
|
+
CreateService = 'bmdextension.createService',
|
40
|
+
CreateApi = 'bmdextension.createApi',
|
41
|
+
CreateEntity = 'bmdextension.createEntity',
|
42
|
+
CreateEntityRequest = 'bmdextension.createEntityRequest',
|
43
|
+
AddModuleContentDefine = 'bmdextension.contentDefine',
|
44
|
+
AddModuleConfiguration = 'bmdextension.configuration',
|
45
|
+
AddProjectName = 'bmdextension.addProject',
|
46
|
+
AddEnum = 'BMD: Add enum',
|
47
|
+
GetProjectDetails = 'bmdextension.getProjectDetails',
|
48
|
+
}
|
49
|
+
|
50
|
+
export enum PropertyType {
|
51
|
+
String = 'STRING',
|
52
|
+
Number = 'NUMBER',
|
53
|
+
Boolean = 'BOOLEAN',
|
54
|
+
Text = 'TEXT',
|
55
|
+
Double = 'DOUBLE',
|
56
|
+
BalanceColumn = 'BALANCE COLUMN',
|
57
|
+
IsBlockColumn = 'IS BLOCK COLUMN',
|
58
|
+
TypeColumn = 'TYPE COLUMN',
|
59
|
+
StatusColumn = 'STATUS COLUMN',
|
60
|
+
IsDeleteColumn = 'IS DELETE COLUMN',
|
61
|
+
}
|
62
|
+
|
63
|
+
export enum Deploy {
|
64
|
+
Deploy = 'bmdextension.deploy',
|
65
|
+
RunDev = 'bmdextension.runDev',
|
66
|
+
RunStart = 'bmdextension.runStart',
|
67
|
+
}
|
68
|
+
|
69
|
+
export enum Confirmation {
|
70
|
+
Yes = 'YES',
|
71
|
+
No = 'NO'
|
72
|
+
}
|
73
|
+
|
74
|
+
export enum TypeRequest {
|
75
|
+
Insert = 'Insert',
|
76
|
+
Update = 'Update'
|
77
|
+
}
|
78
|
+
|
79
|
+
export enum ConstructorFunction {
|
80
|
+
PrivateService = 'bmdextension.insertPrivateService'
|
81
|
+
}
|
82
|
+
|
83
|
+
export const OTHER = 'OTHER'
|