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,192 @@
|
|
1
|
+
import { RoleService } from './../../services/RoleService';
|
2
|
+
// IMPORT LIBRARY
|
3
|
+
import { Controller, Post, UseAuth, Req, Request, Res, Response, HeaderParams, BodyParams, Get, PathParams, QueryParams } from '@tsed/common';
|
4
|
+
import { Docs } from '@tsed/swagger';
|
5
|
+
import Joi from '@hapi/joi';
|
6
|
+
import { Raw } from 'typeorm';
|
7
|
+
|
8
|
+
// IMPORT CUSTOM
|
9
|
+
import { VerificationJWT } from '../../middleware/auth/VerificationJWT';
|
10
|
+
import { Validator } from '../../middleware/validator/Validator';
|
11
|
+
import { Staff } from '../../entity/Staff';
|
12
|
+
import { MultipartFile } from '@tsed/multipartfiles';
|
13
|
+
import config from '../../../config';
|
14
|
+
import { StaffService } from '../../services/StaffService';
|
15
|
+
import JWT, { AuthType } from '../../middleware/auth/strategy/JWT';
|
16
|
+
|
17
|
+
import { Role } from '../../entity/Role';
|
18
|
+
import { StaffUpdate } from '../../entity-request/StaffUpdate';
|
19
|
+
import { Password } from '../../util/password';
|
20
|
+
import CONFIG from '../../../config';
|
21
|
+
|
22
|
+
@Controller("/admin/staff")
|
23
|
+
@Docs("docs_admin")
|
24
|
+
export class StaffController {
|
25
|
+
constructor(
|
26
|
+
private staffService: StaffService,
|
27
|
+
private roleService: RoleService
|
28
|
+
) { }
|
29
|
+
|
30
|
+
|
31
|
+
// =====================GET LIST=====================
|
32
|
+
@Get('')
|
33
|
+
@UseAuth(VerificationJWT)
|
34
|
+
async findAll(
|
35
|
+
@QueryParams('page') page: number,
|
36
|
+
@QueryParams('limit') limit: number,
|
37
|
+
@QueryParams('search') search: string = '',
|
38
|
+
@HeaderParams("token") token: string,
|
39
|
+
@Req() req: Request,
|
40
|
+
@Res() res: Response
|
41
|
+
) {
|
42
|
+
let where = `staff.name LIKE :search`
|
43
|
+
|
44
|
+
const [staffs, total] = await Staff.createQueryBuilder('staff')
|
45
|
+
.where(where, {search: `%${search}%`})
|
46
|
+
.skip((page - 1) * limit)
|
47
|
+
.take(limit)
|
48
|
+
.orderBy('staff.id', 'DESC')
|
49
|
+
.getManyAndCount()
|
50
|
+
|
51
|
+
return res.sendOK({ staffs, total });
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
// =====================CREATE=====================
|
56
|
+
@Post('')
|
57
|
+
@UseAuth(VerificationJWT)
|
58
|
+
@Validator({
|
59
|
+
staff: Joi.required(),
|
60
|
+
roleId: Joi.number().required()
|
61
|
+
})
|
62
|
+
async create(
|
63
|
+
@BodyParams('staff') staff: Staff,
|
64
|
+
@BodyParams('roleId') roleId: number,
|
65
|
+
@HeaderParams("token") token: string,
|
66
|
+
@Req() req: Request,
|
67
|
+
@Res() res: Response,
|
68
|
+
) {
|
69
|
+
await this.staffService.checkDuplicate(staff);
|
70
|
+
|
71
|
+
staff.password = await Password.hash(staff.password);
|
72
|
+
staff.role = new Role();
|
73
|
+
staff.role.id = roleId;
|
74
|
+
delete staff.id;
|
75
|
+
await staff.save();
|
76
|
+
|
77
|
+
return res.sendOK(staff)
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
// =====================UPDATE ADMIN INFO=====================
|
82
|
+
@Post('/:staffId/update')
|
83
|
+
@UseAuth(VerificationJWT)
|
84
|
+
@Validator({
|
85
|
+
staff: Joi.required(),
|
86
|
+
staffId: Joi.number().required()
|
87
|
+
})
|
88
|
+
async update(
|
89
|
+
@BodyParams('staff') staff: StaffUpdate,
|
90
|
+
@BodyParams("roleId") roleId: number,
|
91
|
+
@PathParams('staffId') staffId: number,
|
92
|
+
@HeaderParams("token") token: string,
|
93
|
+
@Req() req: Request,
|
94
|
+
@Res() res: Response,
|
95
|
+
) {
|
96
|
+
await Staff.findOneOrThrowId(staffId);
|
97
|
+
const role = await Role.findOneOrThrowId(roleId)
|
98
|
+
|
99
|
+
const newStaff = staff.toStaff();
|
100
|
+
newStaff.id = staffId;
|
101
|
+
newStaff.role = role
|
102
|
+
await newStaff.save();
|
103
|
+
|
104
|
+
return res.sendOK(staff)
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
// =====================RESET PASSWORD=====================
|
109
|
+
@Post('/:staffId/password/reset')
|
110
|
+
@UseAuth(VerificationJWT)
|
111
|
+
@Validator({
|
112
|
+
newPassword: Joi.string().required(),
|
113
|
+
staffId: Joi.number().required()
|
114
|
+
})
|
115
|
+
async resetPassword(
|
116
|
+
@BodyParams('newPassword') newPassword: string,
|
117
|
+
@PathParams('staffId') staffId: number,
|
118
|
+
@HeaderParams("token") token: string,
|
119
|
+
@Req() req: Request,
|
120
|
+
@Res() res: Response,
|
121
|
+
) {
|
122
|
+
const staff = await Staff.findOneOrThrowId(staffId);
|
123
|
+
staff.password = await Password.hash(newPassword);
|
124
|
+
await staff.save();
|
125
|
+
|
126
|
+
return res.sendOK(staff)
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
// =====================UPDATE ADMIN ROLE=====================
|
131
|
+
@Post('/:staffId/update/role')
|
132
|
+
@UseAuth(VerificationJWT)
|
133
|
+
@Validator({
|
134
|
+
roleId: Joi.number().required(),
|
135
|
+
staffId: Joi.number().required()
|
136
|
+
})
|
137
|
+
async updateRoleAdmin(
|
138
|
+
@BodyParams('roleId') roleId: number,
|
139
|
+
@PathParams('staffId') staffId: number,
|
140
|
+
@HeaderParams("token") token: string,
|
141
|
+
@Req() req: Request,
|
142
|
+
@Res() res: Response,
|
143
|
+
) {
|
144
|
+
const staff = await Staff.findOneOrThrowId(staffId);
|
145
|
+
const role = await Role.findOneOrThrowId(roleId);
|
146
|
+
|
147
|
+
staff.id = staffId;
|
148
|
+
staff.role = role;
|
149
|
+
await staff.save();
|
150
|
+
|
151
|
+
return res.sendOK(staff)
|
152
|
+
}
|
153
|
+
|
154
|
+
|
155
|
+
// =====================INIT=====================
|
156
|
+
@Post('/init')
|
157
|
+
@Validator({
|
158
|
+
bmdPassword: Joi.required()
|
159
|
+
})
|
160
|
+
async init(
|
161
|
+
@Res() res: Response,
|
162
|
+
@Req() req: Request,
|
163
|
+
@BodyParams('bmdPassword') bmdPassword: string,
|
164
|
+
) {
|
165
|
+
if (bmdPassword == 'bmd123456789') {
|
166
|
+
const roleAdmin = await this.roleService.initRole('Admin', 'Quản trị toàn hệ thống')
|
167
|
+
await this.roleService.initRole('User', 'Quản lí một vài tính năng')
|
168
|
+
|
169
|
+
this.staffService.initStaff(roleAdmin, 'Admin', 'admin', 'bmd1234567890')
|
170
|
+
this.staffService.initStaff(roleAdmin, 'Developer', 'develop', 'bmd1234567890')
|
171
|
+
|
172
|
+
return res.sendOK({}, 'Init success')
|
173
|
+
} else {
|
174
|
+
return res.sendClientError('Wrong password')
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
|
179
|
+
// =====================UPLOAD IMAGE=====================
|
180
|
+
@Post('/upload')
|
181
|
+
@UseAuth(VerificationJWT)
|
182
|
+
uploadFile(
|
183
|
+
@HeaderParams("token") token: string,
|
184
|
+
@Req() req: Request,
|
185
|
+
@Res() res: Response,
|
186
|
+
@MultipartFile('file') file: Express.Multer.File,
|
187
|
+
) {
|
188
|
+
file.path = file.path.replace(CONFIG.UPLOAD_DIR, '');
|
189
|
+
return res.sendOK(file)
|
190
|
+
}
|
191
|
+
|
192
|
+
} // END FILE
|
@@ -0,0 +1,170 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Controller, UseAuth, Req, Get, Res, Response, HeaderParams, PathParams, Post, BodyParams } from '@tsed/common';
|
3
|
+
import Joi from '@hapi/joi';
|
4
|
+
import { Docs } from '@tsed/swagger';
|
5
|
+
import { Request } from 'express';
|
6
|
+
|
7
|
+
|
8
|
+
// IMPORT CUSTOM
|
9
|
+
import { Validator } from '../../middleware/validator/Validator';
|
10
|
+
import { VerificationJWT } from '../../middleware/auth/VerificationJWT';
|
11
|
+
import JWT, { AuthType } from '../../middleware/auth/strategy/JWT';
|
12
|
+
import { CustomerService } from '../../services/CustomerService';
|
13
|
+
import { CustomerUpdate } from '../../entity-request/CustomerUpdate';
|
14
|
+
import { Password } from '../../util/password';
|
15
|
+
import { Customer } from '../../entity/Customer';
|
16
|
+
import { getCurrentTimeInt, randomString } from '../../util/helper';
|
17
|
+
import { MailService } from '../../services/MailService';
|
18
|
+
|
19
|
+
|
20
|
+
@Controller("/customer/auth")
|
21
|
+
@Docs("docs_customer")
|
22
|
+
export class AuthController {
|
23
|
+
constructor(
|
24
|
+
private mailService: MailService,
|
25
|
+
private customerService: CustomerService,
|
26
|
+
) { }
|
27
|
+
|
28
|
+
|
29
|
+
// =====================LOGIN=====================
|
30
|
+
@Post('/login')
|
31
|
+
@Validator({
|
32
|
+
phone: Joi.string().required(),
|
33
|
+
password: Joi.string().required()
|
34
|
+
})
|
35
|
+
async login(
|
36
|
+
@HeaderParams("version") version: string,
|
37
|
+
@BodyParams('phone') phone: string,
|
38
|
+
@BodyParams('password') password: string,
|
39
|
+
@BodyParams('expoToken') expoToken: string,
|
40
|
+
@Res() res: Response
|
41
|
+
) {
|
42
|
+
const customer = await this.customerService.login(phone, password);
|
43
|
+
customer.expoToken = expoToken
|
44
|
+
await customer.save()
|
45
|
+
const token = JWT.sign({ id: customer.id, type: AuthType.Customer });
|
46
|
+
|
47
|
+
return res.sendOK({ token })
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
// =====================PROFILE=====================
|
52
|
+
@Get('/profile')
|
53
|
+
@UseAuth(VerificationJWT)
|
54
|
+
async getInfo(
|
55
|
+
@HeaderParams("version") version: string,
|
56
|
+
@HeaderParams("token") token: string,
|
57
|
+
@Req() req: Request,
|
58
|
+
@Res() res: Response,
|
59
|
+
) {
|
60
|
+
return res.sendOK(req.customer)
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
// =====================UPDATE PROFILE=====================
|
65
|
+
@Post('/profile')
|
66
|
+
@UseAuth(VerificationJWT)
|
67
|
+
async updateInfo(
|
68
|
+
@HeaderParams("token") token: string,
|
69
|
+
@HeaderParams("version") version: string,
|
70
|
+
@Req() req: Request,
|
71
|
+
@Res() res: Response,
|
72
|
+
@BodyParams("customer") customerUpdate: CustomerUpdate,
|
73
|
+
) {
|
74
|
+
const customer = customerUpdate.toCustomer()
|
75
|
+
customer.id = req.customer.id
|
76
|
+
|
77
|
+
await customer.save()
|
78
|
+
|
79
|
+
return res.sendOK(customer)
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
// =====================UPDATE PASSWORD=====================
|
84
|
+
@Post('/password/update')
|
85
|
+
@UseAuth(VerificationJWT)
|
86
|
+
@Validator({
|
87
|
+
oldPassword: Joi.string().required(),
|
88
|
+
newPassword: Joi.string().required()
|
89
|
+
})
|
90
|
+
async changePassword(
|
91
|
+
@HeaderParams("version") version: string,
|
92
|
+
@HeaderParams("token") token: string,
|
93
|
+
@Req() req: Request,
|
94
|
+
@Res() res: Response,
|
95
|
+
@BodyParams('oldPassword') oldPassword: string,
|
96
|
+
@BodyParams('newPassword') newPassword: string,
|
97
|
+
) {
|
98
|
+
const { customer } = req;
|
99
|
+
|
100
|
+
await this.customerService.validatePassword(customer, oldPassword)
|
101
|
+
|
102
|
+
if (oldPassword == newPassword) {
|
103
|
+
return res.sendClientError('Mật khẩu mới không được trùng mật khẩu cũ')
|
104
|
+
}
|
105
|
+
|
106
|
+
// Update password
|
107
|
+
customer.password = await Password.hash(newPassword);
|
108
|
+
await customer.save();
|
109
|
+
|
110
|
+
return res.sendOK(customer, 'Cập nhật mật khẩu thành công');
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
// =====================FORGOT=====================
|
115
|
+
@Post('/password/forgot')
|
116
|
+
@Validator({
|
117
|
+
email: Joi.required(),
|
118
|
+
})
|
119
|
+
async forgot(
|
120
|
+
@HeaderParams("version") version: string,
|
121
|
+
@BodyParams("email") email: string,
|
122
|
+
@Req() req: Request,
|
123
|
+
@Res() res: Response,
|
124
|
+
) {
|
125
|
+
const customer = await Customer.findOne({ where: { email } })
|
126
|
+
if (!customer) {
|
127
|
+
return res.sendClientError('Email không tồn tại')
|
128
|
+
}
|
129
|
+
|
130
|
+
const token = JWT.sign({ id: customer.id, type: AuthType.Customer, ia: getCurrentTimeInt() })
|
131
|
+
this.mailService.sendMailLinkReset(token, customer)
|
132
|
+
|
133
|
+
return res.sendOK({}, 'Vui lòng kiểm tra email và truy cập vào đường link xác nhận.')
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
// =====================CONFIRM FORGOT=====================
|
138
|
+
@Post('/password/forgot/confirm')
|
139
|
+
@Validator({
|
140
|
+
token: Joi.required(),
|
141
|
+
})
|
142
|
+
async reForgot(
|
143
|
+
@HeaderParams("version") version: string,
|
144
|
+
@BodyParams("token") token: string,
|
145
|
+
@Req() req: Request,
|
146
|
+
@Res() res: Response,
|
147
|
+
) {
|
148
|
+
const customerId = new JWT().getAuthId(token, AuthType.Customer)
|
149
|
+
|
150
|
+
const customer = await Customer.findOne({ where: { id: customerId } })
|
151
|
+
if (!customer) {
|
152
|
+
return res.sendClientError("Tài khoản không tồn tại")
|
153
|
+
}
|
154
|
+
|
155
|
+
const ia = JWT.getIa(token)
|
156
|
+
if (ia < customer.updatedAt) {
|
157
|
+
return res.sendClientError("Yêu cầu đã hết hạn. Vui lòng gửi yêu cầu khác.")
|
158
|
+
}
|
159
|
+
|
160
|
+
const newPassword = randomString(6)
|
161
|
+
customer.password = await Password.hash(newPassword)
|
162
|
+
await customer.save()
|
163
|
+
|
164
|
+
this.mailService.sendMailReset(newPassword, customer)
|
165
|
+
|
166
|
+
return res.sendOK(customer)
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
} // END FILE
|
@@ -0,0 +1,32 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Request } from 'express';
|
3
|
+
import { Controller, UseAuth, Req, Get, Res, Response, HeaderParams, Post, BodyParams } from '@tsed/common';
|
4
|
+
import Joi from '@hapi/joi';
|
5
|
+
import { Docs } from '@tsed/swagger';
|
6
|
+
import { MultipartFile } from '@tsed/multipartfiles';
|
7
|
+
|
8
|
+
// IMPORT CUSTOM
|
9
|
+
import { VerificationJWT } from '../../middleware/auth/VerificationJWT';
|
10
|
+
import CONFIG from '../../../config';
|
11
|
+
|
12
|
+
@Controller("/customer/customer")
|
13
|
+
@Docs("docs_customer")
|
14
|
+
export class CustomerController {
|
15
|
+
|
16
|
+
constructor() { }
|
17
|
+
|
18
|
+
|
19
|
+
// =====================UPLOAD IMAGE=====================
|
20
|
+
@Post('/upload')
|
21
|
+
@UseAuth(VerificationJWT)
|
22
|
+
uploadFile(
|
23
|
+
@HeaderParams("version") version: string,
|
24
|
+
@HeaderParams('token') token: string,
|
25
|
+
@Res() res: Response,
|
26
|
+
@MultipartFile('file') file: Express.Multer.File,
|
27
|
+
) {
|
28
|
+
file.path = file.path.replace(CONFIG.UPLOAD_DIR, '');
|
29
|
+
return res.sendOK(file)
|
30
|
+
}
|
31
|
+
|
32
|
+
} // END FILE
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { Column, BaseEntity, ObjectType, ObjectID, FindOneOptions, FindConditions, Repository, Connection, PrimaryGeneratedColumn } from "typeorm";
|
2
|
+
import { BadRequest } from "ts-httpexceptions";
|
3
|
+
|
4
|
+
import { getCurrentTimeInt } from "../../util/helper"
|
5
|
+
|
6
|
+
export default class CoreEntity extends BaseEntity {
|
7
|
+
public static connection: Connection;
|
8
|
+
|
9
|
+
constructor() {
|
10
|
+
super()
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
// PROPERTIES
|
15
|
+
|
16
|
+
@PrimaryGeneratedColumn()
|
17
|
+
id: number;
|
18
|
+
|
19
|
+
@Column()
|
20
|
+
createdAt: number;
|
21
|
+
|
22
|
+
@Column()
|
23
|
+
updatedAt: number;
|
24
|
+
|
25
|
+
|
26
|
+
// METHODS
|
27
|
+
|
28
|
+
static getRepository<T extends BaseEntity>(this: ObjectType<T>): Repository<T> {
|
29
|
+
const connection: Connection = (this as any).usedConnection || (this as any).connection;
|
30
|
+
return connection.getRepository<T>(this);
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
save(): Promise<this> {
|
35
|
+
if (!this.hasId()) {
|
36
|
+
this.createdAt = getCurrentTimeInt()
|
37
|
+
}
|
38
|
+
this.updatedAt = getCurrentTimeInt()
|
39
|
+
return super.save()
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
static async findOneOrThrowId<T extends BaseEntity>(
|
44
|
+
this: ObjectType<T>, id?: string | number | Date | ObjectID,
|
45
|
+
options?: FindOneOptions<T>,
|
46
|
+
replaceName?: string
|
47
|
+
): Promise<T> {
|
48
|
+
try {
|
49
|
+
return await super.findOneOrFail<T>(id, options)
|
50
|
+
} catch (error) {
|
51
|
+
console.log(error);
|
52
|
+
throw new BadRequest(`${replaceName ? replaceName : this.name} không tồn tại.`)
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
static async findOneOrThrowOption<T extends BaseEntity>(
|
58
|
+
this: ObjectType<T>,
|
59
|
+
options?: FindOneOptions<T>,
|
60
|
+
replaceName?: string
|
61
|
+
): Promise<T> {
|
62
|
+
try {
|
63
|
+
return await super.findOneOrFail<T>(options)
|
64
|
+
} catch (error) {
|
65
|
+
console.log(error);
|
66
|
+
throw new BadRequest(`${replaceName ? replaceName : this.name} không tồn tại.`)
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
} // END FILE
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Service, AfterRoutesInit } from "@tsed/common";
|
2
|
+
import { TypeORMService } from "@tsed/typeorm";
|
3
|
+
import { Connection, EntityManager } from "typeorm";
|
4
|
+
import CoreEntity from "../entity/CoreEntity";
|
5
|
+
|
6
|
+
@Service()
|
7
|
+
export class CoreService implements AfterRoutesInit {
|
8
|
+
public connection: Connection;
|
9
|
+
public manager: EntityManager
|
10
|
+
|
11
|
+
constructor(
|
12
|
+
public typeORMService: TypeORMService,
|
13
|
+
) { }
|
14
|
+
|
15
|
+
$afterRoutesInit() {
|
16
|
+
this.connection = <any>this.typeORMService.get()
|
17
|
+
this.manager = this.connection.manager
|
18
|
+
CoreEntity.connection = this.connection
|
19
|
+
}
|
20
|
+
|
21
|
+
} // END FILE
|
@@ -0,0 +1,68 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne } from "typeorm";
|
3
|
+
import { Property } from "@tsed/common";
|
4
|
+
|
5
|
+
// IMPORT CUSTOM
|
6
|
+
import { addPrefix } from "../util/helper"
|
7
|
+
import CoreEntity from '../core/entity/CoreEntity';
|
8
|
+
|
9
|
+
export enum GenderType {
|
10
|
+
Male = 'MALE',
|
11
|
+
Female = 'FEMALE'
|
12
|
+
}
|
13
|
+
|
14
|
+
@Entity(addPrefix("customer"))
|
15
|
+
export class Customer extends CoreEntity {
|
16
|
+
constructor() {
|
17
|
+
super()
|
18
|
+
}
|
19
|
+
|
20
|
+
// PROPERTIES
|
21
|
+
|
22
|
+
@Column()
|
23
|
+
@Property()
|
24
|
+
phone: string
|
25
|
+
|
26
|
+
@Column()
|
27
|
+
@Property()
|
28
|
+
name: string;
|
29
|
+
|
30
|
+
@Column({ default: '' })
|
31
|
+
@Property()
|
32
|
+
address: string
|
33
|
+
|
34
|
+
@Column()
|
35
|
+
@Property()
|
36
|
+
password: string
|
37
|
+
|
38
|
+
@Column()
|
39
|
+
@Property()
|
40
|
+
email: string
|
41
|
+
|
42
|
+
@Column({ default: GenderType.Male })
|
43
|
+
@Property()
|
44
|
+
gender: string
|
45
|
+
|
46
|
+
@Column({ nullable: true })
|
47
|
+
@Property()
|
48
|
+
avatar: string;
|
49
|
+
|
50
|
+
@Column({ nullable: true })
|
51
|
+
@Property()
|
52
|
+
expoToken: string;
|
53
|
+
|
54
|
+
@Column({ default: false })
|
55
|
+
@Property()
|
56
|
+
isBlock: boolean
|
57
|
+
|
58
|
+
@Column({ default: false, select: false })
|
59
|
+
@Property()
|
60
|
+
isDeleted: boolean
|
61
|
+
|
62
|
+
// RELATIONS
|
63
|
+
|
64
|
+
|
65
|
+
// METHODS
|
66
|
+
|
67
|
+
|
68
|
+
} // END FILE
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, ManyToMany, JoinTable } from "typeorm";
|
2
|
+
import { Property } from "@tsed/common";
|
3
|
+
|
4
|
+
import { addPrefix } from "../util/helper"
|
5
|
+
import CoreEntity from '../core/entity/CoreEntity';
|
6
|
+
import { Role } from "./Role";
|
7
|
+
|
8
|
+
@Entity(addPrefix("permission"))
|
9
|
+
export class Permission extends CoreEntity {
|
10
|
+
constructor() {
|
11
|
+
super()
|
12
|
+
}
|
13
|
+
|
14
|
+
// PROPERTIES
|
15
|
+
|
16
|
+
@Column()
|
17
|
+
@Property()
|
18
|
+
path: string;
|
19
|
+
|
20
|
+
|
21
|
+
// RELATIONS
|
22
|
+
|
23
|
+
@ManyToMany(type => Role, role => role.permissions)
|
24
|
+
@JoinTable()
|
25
|
+
roles: Role[]
|
26
|
+
|
27
|
+
// METHODS
|
28
|
+
|
29
|
+
} // END FILE
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, ManyToMany } from "typeorm";
|
2
|
+
import { Property } from "@tsed/common";
|
3
|
+
|
4
|
+
import { addPrefix } from "../util/helper"
|
5
|
+
import CoreEntity from '../core/entity/CoreEntity';
|
6
|
+
import { Permission } from "./Permission";
|
7
|
+
import { Staff } from "./Staff";
|
8
|
+
|
9
|
+
@Entity(addPrefix("role"))
|
10
|
+
export class Role extends CoreEntity {
|
11
|
+
constructor() {
|
12
|
+
super()
|
13
|
+
}
|
14
|
+
|
15
|
+
// PROPERTIES
|
16
|
+
|
17
|
+
@Column()
|
18
|
+
@Property()
|
19
|
+
name: string;
|
20
|
+
|
21
|
+
@Column()
|
22
|
+
@Property()
|
23
|
+
description: string
|
24
|
+
|
25
|
+
|
26
|
+
// RELATIONS
|
27
|
+
|
28
|
+
@OneToMany(() => Staff, admin => admin.role)
|
29
|
+
staff: Staff[]
|
30
|
+
|
31
|
+
@ManyToMany(() => Permission, permission => permission.roles)
|
32
|
+
permissions: Permission[]
|
33
|
+
|
34
|
+
// METHODS
|
35
|
+
|
36
|
+
} // END FILE
|
@@ -0,0 +1,54 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, ManyToMany } from "typeorm";
|
3
|
+
import { Property } from "@tsed/common";
|
4
|
+
|
5
|
+
// IMPORT CUSTOM
|
6
|
+
import { addPrefix } from "../util/helper"
|
7
|
+
import CoreEntity from '../core/entity/CoreEntity';
|
8
|
+
import { Role } from "./Role";
|
9
|
+
|
10
|
+
@Entity(addPrefix("staff"))
|
11
|
+
export class Staff extends CoreEntity {
|
12
|
+
constructor() {
|
13
|
+
super()
|
14
|
+
}
|
15
|
+
|
16
|
+
// PROPERTIES
|
17
|
+
|
18
|
+
@Column()
|
19
|
+
@Property()
|
20
|
+
username: string;
|
21
|
+
|
22
|
+
@Column({ select: false })
|
23
|
+
password: string;
|
24
|
+
|
25
|
+
@Column({ default: "" })
|
26
|
+
@Property()
|
27
|
+
name: string;
|
28
|
+
|
29
|
+
@Column({ default: "" })
|
30
|
+
@Property()
|
31
|
+
avatar: string;
|
32
|
+
|
33
|
+
@Column({ default: "" })
|
34
|
+
@Property()
|
35
|
+
phone: string
|
36
|
+
|
37
|
+
@Column({ default: "" })
|
38
|
+
@Property()
|
39
|
+
email: string
|
40
|
+
|
41
|
+
@Column({ default: false })
|
42
|
+
@Property()
|
43
|
+
isBlock: boolean
|
44
|
+
|
45
|
+
// RELATIONS
|
46
|
+
|
47
|
+
@ManyToOne(type => Role, role => role.staff)
|
48
|
+
role: Role;
|
49
|
+
|
50
|
+
|
51
|
+
// METHODS
|
52
|
+
|
53
|
+
|
54
|
+
} // END FILE
|