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
package/src/API.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
export const API = {
|
2
|
+
Project: {
|
3
|
+
get: 'https://extension.bmdapp.store:3005/v1/admin/project',
|
4
|
+
post: `https://extension.bmdapp.store:3005/v1/admin/project`
|
5
|
+
},
|
6
|
+
Interface: {
|
7
|
+
get: `https://extension.bmdapp.store:3005/v1/admin/interface`,
|
8
|
+
post: `https://extension.bmdapp.store:3005/v1/admin/interface`
|
9
|
+
},
|
10
|
+
Enum: {
|
11
|
+
get: `https://extension.bmdapp.store:3005/v1/admin/enum`,
|
12
|
+
post: `https://extension.bmdapp.store:3005/v1/admin/enum`
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import * as path from 'path'
|
3
|
+
import fsExtra = require('fs-extra');
|
4
|
+
import { replaceSymbolTemplate, getFullTextType } from './util';
|
5
|
+
export const ROOT_PATH = vscode.workspace.rootPath as string
|
6
|
+
|
7
|
+
interface KeywordPair {
|
8
|
+
regex: RegExp,
|
9
|
+
value: any
|
10
|
+
}
|
11
|
+
|
12
|
+
export class FSProvider {
|
13
|
+
|
14
|
+
static checkExistProject(): boolean {
|
15
|
+
vscode.window.showInformationMessage('check project')
|
16
|
+
const packageJson = path.join(ROOT_PATH, 'package.json');
|
17
|
+
const env = path.join(ROOT_PATH, '.env');
|
18
|
+
const srcFolder = path.join(ROOT_PATH, 'src');
|
19
|
+
vscode.window.showInformationMessage('check project xong')
|
20
|
+
return fsExtra.existsSync(packageJson) ||
|
21
|
+
fsExtra.existsSync(env) ||
|
22
|
+
fsExtra.existsSync(srcFolder)
|
23
|
+
}
|
24
|
+
|
25
|
+
static isEntity(entity: string) {
|
26
|
+
const entities = FSProvider.getAllFileInFolder('/src/entity')
|
27
|
+
let name = getFullTextType(entity).classifyCase
|
28
|
+
|
29
|
+
return entities.includes(name)
|
30
|
+
}
|
31
|
+
|
32
|
+
static checkExist(distPath: string): boolean {
|
33
|
+
const file = path.join(ROOT_PATH, distPath);
|
34
|
+
return fsExtra.existsSync(file)
|
35
|
+
}
|
36
|
+
|
37
|
+
static copyFile(assetPathFrom: string, pathTo: string) {
|
38
|
+
try {
|
39
|
+
const fullPath = path.join(ROOT_PATH, pathTo);
|
40
|
+
fsExtra.copy(__dirname + '/assets/' + assetPathFrom, fullPath)
|
41
|
+
} catch (error) {
|
42
|
+
console.log('Error write file:', error)
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
static copyAndReplaceFile(assetPathFrom: string, pathTo: string, keywords: KeywordPair[]) {
|
47
|
+
const fullPath = path.join(ROOT_PATH, pathTo);
|
48
|
+
|
49
|
+
try {
|
50
|
+
const buffer = fsExtra.readFileSync(__dirname + '/assets/' + assetPathFrom)
|
51
|
+
let content = buffer.toString()
|
52
|
+
|
53
|
+
content = replaceSymbolTemplate(content)
|
54
|
+
keywords.forEach(pair => {
|
55
|
+
content = content.replace(pair.regex, pair.value)
|
56
|
+
});
|
57
|
+
fsExtra.ensureFileSync(fullPath)
|
58
|
+
fsExtra.writeFileSync(fullPath, content)
|
59
|
+
} catch (error) {
|
60
|
+
console.error('copyAndReplaceFile error', error);
|
61
|
+
|
62
|
+
if (error instanceof Error) {
|
63
|
+
vscode.window.showErrorMessage(error.message)
|
64
|
+
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
}
|
69
|
+
|
70
|
+
static makeFolder(folderPath: string) {
|
71
|
+
const fullPath = path.join(ROOT_PATH, folderPath);
|
72
|
+
fsExtra.ensureDirSync(fullPath)
|
73
|
+
}
|
74
|
+
|
75
|
+
static getAllFileInFolder(folderPath: string) {
|
76
|
+
const fullPath = path.join(ROOT_PATH, folderPath);
|
77
|
+
const files = fsExtra.readdirSync(fullPath)
|
78
|
+
return files.filter(e => e.includes('.ts')).map(file => file = file.replace('.ts', ''))
|
79
|
+
}
|
80
|
+
|
81
|
+
static getLinesDocumentInFile(folderPath: string) {
|
82
|
+
try {
|
83
|
+
const fullPath = path.join(ROOT_PATH, folderPath);
|
84
|
+
const files = fsExtra.readFileSync(fullPath)
|
85
|
+
const lines = files.toString().split('\n').map(line => line.trim())
|
86
|
+
return lines || []
|
87
|
+
} catch (error) {
|
88
|
+
return []
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
static getContentInFile(filePath: string) {
|
93
|
+
const fullPath = path.join(ROOT_PATH, filePath);
|
94
|
+
const files = fsExtra.readFileSync(fullPath)
|
95
|
+
return files.toString()
|
96
|
+
}
|
97
|
+
|
98
|
+
static isValidStructure() {
|
99
|
+
return FSProvider.checkExist('src/Server.ts')
|
100
|
+
}
|
101
|
+
|
102
|
+
static getFullPath(pathStr: string) {
|
103
|
+
return path.join(ROOT_PATH, pathStr);
|
104
|
+
}
|
105
|
+
}
|
package/src/Request.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import Axios from "axios";
|
2
|
+
import * as vscode from 'vscode';
|
3
|
+
import { Password } from "./utils/Password";
|
4
|
+
|
5
|
+
export class Request {
|
6
|
+
|
7
|
+
static async get(url: string, params?: any) {
|
8
|
+
const password = Password.getProjectPassword()
|
9
|
+
return Axios.get(url, { params: params || null, headers: { password } }).then(res => res.data).catch(error => {
|
10
|
+
console.log('error:', error?.response?.data?.message)
|
11
|
+
vscode.window.showInformationMessage(`Error: ${error?.response?.data?.message || "Lỗi rồi."}`);
|
12
|
+
})
|
13
|
+
}
|
14
|
+
|
15
|
+
static async post(url: string, data: any) {
|
16
|
+
const password = Password.getApiPassword();
|
17
|
+
|
18
|
+
return Axios.post(url, data, { headers: { token: password } }).then(res => res.data).catch(error => {
|
19
|
+
console.log('error:', error?.response?.data?.message)
|
20
|
+
|
21
|
+
vscode.window.showInformationMessage(`Error: ${error?.response?.data?.message || "Lỗi rồi."}`);
|
22
|
+
})
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { request } from "@/utils/request";
|
2
|
+
import { AxiosPromise } from "axios";
|
3
|
+
|
4
|
+
export const {{entity}}Api = {
|
5
|
+
findAll: (params?: any): AxiosPromise<any> =>
|
6
|
+
request({
|
7
|
+
url: "/v1/{{module}}/{{entity}}",
|
8
|
+
params,
|
9
|
+
}),
|
10
|
+
create: (data: any): AxiosPromise<any> =>
|
11
|
+
request({
|
12
|
+
url: "/v1/{{module}}/{{entity}}",
|
13
|
+
data,
|
14
|
+
method: "post",
|
15
|
+
}),
|
16
|
+
update: (id: number, data: any): AxiosPromise<any> =>
|
17
|
+
request({
|
18
|
+
url: `/v1/{{module}}/{{entity}}/${id}`,
|
19
|
+
method: "patch",
|
20
|
+
data,
|
21
|
+
}),
|
22
|
+
delete: (id: number): AxiosPromise<any> =>
|
23
|
+
request({
|
24
|
+
url: `/v1/{{module}}/{{entity}}/${id}`,
|
25
|
+
method: "delete",
|
26
|
+
}),
|
27
|
+
};
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { Controller, Post, UseAuth, Req, Request, Res, Response, HeaderParams, BodyParams, Get, PathParams, QueryParams } from '@tsed/common';
|
2
|
+
import { Docs } from '@tsed/swagger';
|
3
|
+
import Joi from '@hapi/joi';
|
4
|
+
import { Like } from 'typeorm';
|
5
|
+
|
6
|
+
import { VerificationJWT } from '../../middleware/auth/VerificationJWT';
|
7
|
+
import { Validator } from '../../middleware/validator/Validator';
|
8
|
+
import { Configuration, ConfigurationParams } from '../../entity/Configuration';
|
9
|
+
import { ConfigurationService } from '../../services/ConfigurationService';
|
10
|
+
|
11
|
+
|
12
|
+
@Controller("/admin/configuration")
|
13
|
+
@Docs("docs_admin")
|
14
|
+
export class ConfigurationController {
|
15
|
+
constructor(
|
16
|
+
private configurationService: ConfigurationService
|
17
|
+
) { }
|
18
|
+
|
19
|
+
|
20
|
+
// =====================GET LIST=====================
|
21
|
+
@Get('')
|
22
|
+
@UseAuth(VerificationJWT)
|
23
|
+
@Validator({})
|
24
|
+
async findAll(
|
25
|
+
@HeaderParams("token") token: string,
|
26
|
+
@Req() req: Request,
|
27
|
+
@Res() res: Response
|
28
|
+
) {
|
29
|
+
const config = await Configuration.find({ order: { id: "DESC" } })
|
30
|
+
|
31
|
+
return res.sendOK(config)
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
// =====================INIT=====================
|
36
|
+
@Post('/init')
|
37
|
+
@UseAuth(VerificationJWT)
|
38
|
+
async init(
|
39
|
+
@Req() req: Request,
|
40
|
+
@Res() res: Response,
|
41
|
+
@HeaderParams("token") token: string,
|
42
|
+
) {
|
43
|
+
await Configuration.delete({})
|
44
|
+
await this.configurationService.init(ConfigurationParams.CommissionTransport, 10, 'Chiết khấu tài xế phải trả')
|
45
|
+
await this.configurationService.init(ConfigurationParams.DistanceFindDriver, 10, 'Phạm vi bán kính để tìm tài xế xung quanh')
|
46
|
+
await this.configurationService.init(ConfigurationParams.MinDriverBalance, 10000, 'Tài khoản tài xế cần tối thiểu')
|
47
|
+
return res.sendOK({}, 'Init success')
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
// =====================UPDATE ITEM=====================
|
52
|
+
@Post('/:configId/update')
|
53
|
+
@UseAuth(VerificationJWT)
|
54
|
+
@Validator({
|
55
|
+
config: Joi.required(),
|
56
|
+
configId: Joi.number().required()
|
57
|
+
})
|
58
|
+
async update(
|
59
|
+
@Req() req: Request,
|
60
|
+
@Res() res: Response,
|
61
|
+
@HeaderParams("token") token: string,
|
62
|
+
@BodyParams("config") config: Configuration,
|
63
|
+
@PathParams("configId") configId: number,
|
64
|
+
) {
|
65
|
+
await Configuration.findOneOrThrowId(+configId)
|
66
|
+
config.id = +configId
|
67
|
+
await config.save()
|
68
|
+
|
69
|
+
return res.sendOK(config)
|
70
|
+
}
|
71
|
+
|
72
|
+
} // END FILE
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
|
2
|
+
import { addPrefix } from "../util/helper"
|
3
|
+
import CoreEntity from '../core/entity/CoreEntity';
|
4
|
+
import { Property } from "@tsed/common";
|
5
|
+
|
6
|
+
export enum ConfigurationParams {
|
7
|
+
MinPrice = 'MIN_PRICE',
|
8
|
+
}
|
9
|
+
|
10
|
+
@Entity(addPrefix("config"))
|
11
|
+
export class Configuration extends CoreEntity {
|
12
|
+
constructor() {
|
13
|
+
super()
|
14
|
+
}
|
15
|
+
|
16
|
+
// PROPERTIES
|
17
|
+
|
18
|
+
@Column()
|
19
|
+
@Property()
|
20
|
+
param: string
|
21
|
+
|
22
|
+
@Column()
|
23
|
+
@Property()
|
24
|
+
value: string;
|
25
|
+
|
26
|
+
@Column({ default: '' })
|
27
|
+
@Property()
|
28
|
+
note: string
|
29
|
+
|
30
|
+
|
31
|
+
// RELATIONS
|
32
|
+
|
33
|
+
|
34
|
+
// METHODS
|
35
|
+
|
36
|
+
|
37
|
+
} // END FILE
|
@@ -0,0 +1,26 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Service } from "@tsed/common";
|
3
|
+
|
4
|
+
|
5
|
+
// IMPORT CUSTOM
|
6
|
+
import { Configuration, ConfigurationParams } from "../entity/Configuration";
|
7
|
+
|
8
|
+
|
9
|
+
@Service()
|
10
|
+
export class ConfigurationService {
|
11
|
+
|
12
|
+
public async getParam(param: ConfigurationParams) {
|
13
|
+
const config = await Configuration.findOne({
|
14
|
+
where: { param }
|
15
|
+
})
|
16
|
+
return config.value || null
|
17
|
+
}
|
18
|
+
|
19
|
+
public async initParam(param: ConfigurationParams, value: string) {
|
20
|
+
const configuration = new Configuration()
|
21
|
+
configuration.param = param
|
22
|
+
configuration.value = value
|
23
|
+
await configuration.save()
|
24
|
+
}
|
25
|
+
|
26
|
+
} //END FILE
|
@@ -0,0 +1,91 @@
|
|
1
|
+
import { ContentDefineService } from './../../services/ContentDefineService';
|
2
|
+
import { Controller, Post, UseAuth, Res, Response, HeaderParams, BodyParams, Get, PathParams, Req, Request } from '@tsed/common';
|
3
|
+
import { Docs } from '@tsed/swagger';
|
4
|
+
import Joi from '@hapi/joi';
|
5
|
+
import { VerificationJWT } from '../../middleware/auth/VerificationJWT';
|
6
|
+
import { Validator } from '../../middleware/validator/Validator';
|
7
|
+
import { ContentDefine, ContentDefineType } from '../../entity/ContentDefine';
|
8
|
+
import faker from 'faker'
|
9
|
+
import { MultipartFile } from '@tsed/multipartfiles';
|
10
|
+
import CONFIG from '../../../config';
|
11
|
+
|
12
|
+
|
13
|
+
@Controller("/admin/contentDefine")
|
14
|
+
@Docs("docs_admin")
|
15
|
+
export class ContentDefineController {
|
16
|
+
constructor(
|
17
|
+
private contentDefineService: ContentDefineService
|
18
|
+
) { }
|
19
|
+
|
20
|
+
|
21
|
+
// =====================GET LIST=====================
|
22
|
+
@Get('')
|
23
|
+
@UseAuth(VerificationJWT)
|
24
|
+
@Validator({
|
25
|
+
})
|
26
|
+
async findAll(
|
27
|
+
@HeaderParams("token") token: string,
|
28
|
+
@Res() res: Response,
|
29
|
+
@Req() req: Request,
|
30
|
+
) {
|
31
|
+
const contentDefines = await ContentDefine.find()
|
32
|
+
|
33
|
+
return res.sendOK(contentDefines)
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
// =====================UPDATE ITEM=====================
|
38
|
+
@Post('/:contentDefineId/update')
|
39
|
+
@UseAuth(VerificationJWT)
|
40
|
+
@Validator({
|
41
|
+
contentDefine: Joi.required(),
|
42
|
+
})
|
43
|
+
async update(
|
44
|
+
@HeaderParams('token') token: string,
|
45
|
+
@Res() res: Response,
|
46
|
+
@Req() req: Request,
|
47
|
+
@BodyParams("contentDefine") contentDefine: ContentDefine,
|
48
|
+
@PathParams("contentDefineId") contentDefineId: number,
|
49
|
+
) {
|
50
|
+
await ContentDefine.findOneOrThrowId(+contentDefineId)
|
51
|
+
contentDefine.id = contentDefineId
|
52
|
+
await contentDefine.save()
|
53
|
+
|
54
|
+
return res.sendOK(contentDefine)
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
// =====================INIT=====================
|
59
|
+
@Post('/init')
|
60
|
+
@UseAuth(VerificationJWT)
|
61
|
+
@Validator({
|
62
|
+
})
|
63
|
+
async init(
|
64
|
+
@HeaderParams("token") token: string,
|
65
|
+
@Res() res: Response,
|
66
|
+
@Req() req: Request,
|
67
|
+
) {
|
68
|
+
await ContentDefine.delete({})
|
69
|
+
this.contentDefineService.initContentDefine(ContentDefineType.About, 'Giới thiệu', faker.random.words(100))
|
70
|
+
this.contentDefineService.initContentDefine(ContentDefineType.Faq, 'Câu hỏi thường gặp', faker.random.words(100))
|
71
|
+
this.contentDefineService.initContentDefine(ContentDefineType.Security, 'Bảo mật', faker.random.words(100))
|
72
|
+
this.contentDefineService.initContentDefine(ContentDefineType.HowToUse, 'Hướng dẫn sử dụng', faker.random.words(100))
|
73
|
+
this.contentDefineService.initContentDefine(ContentDefineType.TermCondition, 'Điều khoản sử dụng', faker.random.words(100))
|
74
|
+
return res.sendOK({}, 'Init success')
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
// =====================UPLOAD IMAGE=====================
|
79
|
+
@Post('/upload')
|
80
|
+
@UseAuth(VerificationJWT)
|
81
|
+
uploadFile(
|
82
|
+
@HeaderParams('token') token: string,
|
83
|
+
@Res() res: Response,
|
84
|
+
@Req() req: Request,
|
85
|
+
@MultipartFile('file') file: Express.Multer.File,
|
86
|
+
) {
|
87
|
+
file.path = file.path.replace(CONFIG.UPLOAD_DIR, '');
|
88
|
+
return res.sendOK(file);
|
89
|
+
}
|
90
|
+
|
91
|
+
} // END FILE
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
|
2
|
+
import { addPrefix } from "../util/helper"
|
3
|
+
import CoreEntity from '../core/entity/CoreEntity';
|
4
|
+
import { Property } from "@tsed/common";
|
5
|
+
|
6
|
+
export enum ContentDefineType {
|
7
|
+
About = "ABOUT",
|
8
|
+
Faq = "FAQ",
|
9
|
+
HowToUse = "HOW_TO_USE",
|
10
|
+
Security = "SECURITY",
|
11
|
+
TermCondition = "TERM_CONDITION"
|
12
|
+
}
|
13
|
+
|
14
|
+
@Entity(addPrefix("content_define"))
|
15
|
+
export class ContentDefine extends CoreEntity {
|
16
|
+
constructor() {
|
17
|
+
super()
|
18
|
+
}
|
19
|
+
|
20
|
+
// PROPERTIES
|
21
|
+
|
22
|
+
@Column()
|
23
|
+
@Property()
|
24
|
+
title: string;
|
25
|
+
|
26
|
+
@Column()
|
27
|
+
@Property()
|
28
|
+
image: string
|
29
|
+
|
30
|
+
@Column({ type: "text" })
|
31
|
+
@Property()
|
32
|
+
body: string
|
33
|
+
|
34
|
+
@Column()
|
35
|
+
@Property()
|
36
|
+
type: string;
|
37
|
+
|
38
|
+
|
39
|
+
// RELATIONS
|
40
|
+
|
41
|
+
|
42
|
+
// METHODS
|
43
|
+
|
44
|
+
|
45
|
+
} // END FILE
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Service } from "@tsed/common";
|
3
|
+
|
4
|
+
|
5
|
+
// IMPORT CUSTOM
|
6
|
+
import { ContentDefine, ContentDefineType } from "../entity/ContentDefine";
|
7
|
+
|
8
|
+
@Service()
|
9
|
+
export class ContentDefineService {
|
10
|
+
|
11
|
+
public async initContentDefine(type: ContentDefineType, title: string, body: string) {
|
12
|
+
const content = new ContentDefine()
|
13
|
+
content.title = title
|
14
|
+
content.body = body
|
15
|
+
content.type = type
|
16
|
+
await content.save()
|
17
|
+
}
|
18
|
+
|
19
|
+
} //END FILE
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { Controller, UseAuth, Req, Get, Res, Response, HeaderParams, PathParams, QueryParams } from '@tsed/common';
|
2
|
+
import Joi from '@hapi/joi';
|
3
|
+
import { Docs } from '@tsed/swagger';
|
4
|
+
import { Request } from 'express';
|
5
|
+
|
6
|
+
import { Validator } from '../../middleware/validator/Validator';
|
7
|
+
import { VerificationJWT } from '../../middleware/auth/VerificationJWT';
|
8
|
+
import { ContentDefine, ContentDefineType } from '../../entity/ContentDefine';
|
9
|
+
|
10
|
+
@Controller("/customer/contentDefine")
|
11
|
+
@Docs("docs_customer")
|
12
|
+
export class ContentDefineController {
|
13
|
+
constructor() { }
|
14
|
+
|
15
|
+
|
16
|
+
// =====================GET ITEM=====================
|
17
|
+
@Get('')
|
18
|
+
@UseAuth(VerificationJWT)
|
19
|
+
@Validator({
|
20
|
+
type: Joi.string().required()
|
21
|
+
})
|
22
|
+
async findAll(
|
23
|
+
@HeaderParams("token") token: string,
|
24
|
+
@QueryParams("type") type: ContentDefineType,
|
25
|
+
@Req() req: Request,
|
26
|
+
@Res() res: Response
|
27
|
+
) {
|
28
|
+
const content = await ContentDefine.findOneOrThrowOption({
|
29
|
+
where: { type }
|
30
|
+
})
|
31
|
+
return res.sendOK(content)
|
32
|
+
}
|
33
|
+
|
34
|
+
} // END FILE
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Controller, UseAuth, Req, Get, Res, Response, HeaderParams, PathParams, QueryParams } 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 { {{classify}} } from '../../entity/{{classify}}';
|
12
|
+
import { {{classify}}Service } from '../../services/{{classify}}Service';
|
13
|
+
|
14
|
+
@Controller("{{controller}}")
|
15
|
+
@Docs("docs_{{docs}}")
|
16
|
+
export class {{classify}}Controller {
|
17
|
+
constructor(
|
18
|
+
private {{camel}}Service: {{classify}}Service
|
19
|
+
) {}
|
20
|
+
|
21
|
+
|
22
|
+
// =====================GET LIST=====================
|
23
|
+
@Get('')
|
24
|
+
@UseAuth(VerificationJWT)
|
25
|
+
@Validator({
|
26
|
+
page: Joi.number().min(1),
|
27
|
+
limit: Joi.number().min(1).max(100)
|
28
|
+
})
|
29
|
+
async findAll(
|
30
|
+
@HeaderParams("token") token: string,
|
31
|
+
@QueryParams("page") page: number = 1,
|
32
|
+
@QueryParams("limit") limit: number = 10,
|
33
|
+
@QueryParams("search") search: string = "",
|
34
|
+
@Req() req: Request,
|
35
|
+
@Res() res: Response
|
36
|
+
) {
|
37
|
+
const { {{camel}}s, total } = await this.{{camel}}Service.getManyAndCount({
|
38
|
+
limit,
|
39
|
+
search,
|
40
|
+
page
|
41
|
+
})
|
42
|
+
|
43
|
+
return res.sendOK({ {{camel}}s, total });
|
44
|
+
}
|
45
|
+
|
46
|
+
} // END FILE
|
@@ -0,0 +1,103 @@
|
|
1
|
+
// IMPORT LIBRARY
|
2
|
+
import { Controller, Post, UseAuth, Req, Request, Res, Response, HeaderParams, BodyParams, Get, PathParams, QueryParams, Delete, Patch } from '@tsed/common';
|
3
|
+
import { Docs } from '@tsed/swagger';
|
4
|
+
import Joi from '@hapi/joi';
|
5
|
+
|
6
|
+
|
7
|
+
// IMPORT CUSTOM
|
8
|
+
import { VerificationJWT } from '../../middleware/auth/VerificationJWT';
|
9
|
+
import { Validator } from '../../middleware/validator/Validator';
|
10
|
+
import { {{classify}} } from '../../entity/{{classify}}';
|
11
|
+
import { {{classify}}Service } from '../../services/{{classify}}Service';
|
12
|
+
|
13
|
+
@Controller("{{controller}}")
|
14
|
+
@Docs("docs_{{docs}}")
|
15
|
+
export class {{classify}}Controller {
|
16
|
+
constructor(
|
17
|
+
private {{camel}}Service: {{classify}}Service
|
18
|
+
) { }
|
19
|
+
|
20
|
+
|
21
|
+
// =====================GET LIST=====================
|
22
|
+
@Get('')
|
23
|
+
@UseAuth(VerificationJWT)
|
24
|
+
@Validator({
|
25
|
+
page: Joi.number().min(1),
|
26
|
+
limit: Joi.number().min(1).max(100)
|
27
|
+
})
|
28
|
+
async findAll(
|
29
|
+
@HeaderParams("token") token: string,
|
30
|
+
@QueryParams("page") page: number = 1,
|
31
|
+
@QueryParams("limit") limit: number = 10,
|
32
|
+
@QueryParams("search") search: string = "",
|
33
|
+
@Req() req: Request,
|
34
|
+
@Res() res: Response
|
35
|
+
) {
|
36
|
+
const { {{camel}}s, total } = await this.{{camel}}Service.getManyAndCount({
|
37
|
+
limit,
|
38
|
+
search,
|
39
|
+
page
|
40
|
+
})
|
41
|
+
|
42
|
+
return res.sendOK({ {{camel}}s, total });
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
// =====================CREATE ITEM=====================
|
47
|
+
@Post('')
|
48
|
+
@UseAuth(VerificationJWT)
|
49
|
+
@Validator({
|
50
|
+
{{camel}}: Joi.required(),
|
51
|
+
})
|
52
|
+
async create(
|
53
|
+
@HeaderParams("token") token: string,
|
54
|
+
@Req() req: Request,
|
55
|
+
@Res() res: Response,
|
56
|
+
@BodyParams("{{camel}}") {{camel}}: {{classify}},
|
57
|
+
) {
|
58
|
+
await {{camel}}.save()
|
59
|
+
return res.sendOK({{camel}})
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
// =====================UPDATE ITEM=====================
|
64
|
+
@Patch('/:{{camel}}Id')
|
65
|
+
@UseAuth(VerificationJWT)
|
66
|
+
@Validator({
|
67
|
+
{{camel}}: Joi.required(),
|
68
|
+
{{camel}}Id: Joi.number().required()
|
69
|
+
})
|
70
|
+
async update(
|
71
|
+
@HeaderParams("token") token: string,
|
72
|
+
@Req() req: Request,
|
73
|
+
@Res() res: Response,
|
74
|
+
@BodyParams("{{camel}}") {{camel}}: {{classify}},
|
75
|
+
@PathParams("{{camel}}Id") {{camel}}Id: number,
|
76
|
+
) {
|
77
|
+
await {{classify}}.findOneOrThrowId({{camel}}Id)
|
78
|
+
{{camel}}.id = +{{camel}}Id
|
79
|
+
await {{camel}}.save()
|
80
|
+
|
81
|
+
return res.sendOK({{camel}})
|
82
|
+
}
|
83
|
+
|
84
|
+
// =====================UPDATE ITEM=====================
|
85
|
+
@Delete('/:{{camel}}Id')
|
86
|
+
@UseAuth(VerificationJWT)
|
87
|
+
@Validator({
|
88
|
+
{{camel}}Id: Joi.number().required()
|
89
|
+
})
|
90
|
+
async delete(
|
91
|
+
@HeaderParams("token") token: string,
|
92
|
+
@Req() req: Request,
|
93
|
+
@Res() res: Response,
|
94
|
+
@PathParams("{{camel}}Id") {{camel}}Id: number,
|
95
|
+
) {
|
96
|
+
const {{camel}} = await {{classify}}.findOneOrThrowId({{camel}}Id)
|
97
|
+
{{camel}}.isDeleted = true;
|
98
|
+
await {{camel}}.save()
|
99
|
+
|
100
|
+
return res.sendOK({{camel}})
|
101
|
+
}
|
102
|
+
|
103
|
+
} // END FILE
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Entity, Column } from "typeorm";
|
2
|
+
import { Property } from "@tsed/schema";
|
3
|
+
|
4
|
+
import { addPrefix } from "../util/helper"
|
5
|
+
import CoreEntity from '../core/entity/CoreEntity';
|
6
|
+
|
7
|
+
@Entity(addPrefix("{{snake}}"))
|
8
|
+
export class {{classify}} extends CoreEntity {
|
9
|
+
constructor() {
|
10
|
+
super()
|
11
|
+
}
|
12
|
+
|
13
|
+
// PROPERTIES
|
14
|
+
|
15
|
+
|
16
|
+
// RELATIONS
|
17
|
+
|
18
|
+
|
19
|
+
// METHODS
|
20
|
+
|
21
|
+
|
22
|
+
} // END FILE
|