-
Notifications
You must be signed in to change notification settings - Fork 53
feat:add component and componentLibrary #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "editor.codeActionsOnSave": { | ||
| "source.fixAll.eslint": true | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * Copyright (c) 2023 - present TinyEngine Authors. | ||
| * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license. | ||
| * | ||
| * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, | ||
| * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR | ||
| * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. | ||
| * | ||
| */ | ||
| import { Controller } from 'egg'; | ||
| import { I_CreateComponentLibrary } from '../../lib/interface'; | ||
|
|
||
| export default class ComponentController extends Controller { | ||
|
|
||
| /** | ||
| * @summary 注册组件库 | ||
| * @router POST /api/componentLibrary/create | ||
| */ | ||
| async create(){ | ||
| const data: I_CreateComponentLibrary = this.ctx.request.body; | ||
| this.ctx.body = await this.service.materialCenter.componentLibrary.create(data); | ||
| } | ||
|
|
||
| /** | ||
| * @summary 查询组件库 | ||
| * @router GET | ||
| */ | ||
| async find(){ | ||
| this.ctx.body = await this.service.materialCenter.componentLibrary.find(this.ctx.query); | ||
| } | ||
|
|
||
| /** | ||
| * @summary 更新组件库 | ||
| * @router PUT | ||
| */ | ||
| async update(){ | ||
| const { id } = this.ctx.params; | ||
| const params = this.ctx.request.body; | ||
| this.ctx.body = await this.service.materialCenter.componentLibrary.update({id, ...params }); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @summary 删除组件库 | ||
| * @router DELETE | ||
| */ | ||
| async delete(){ | ||
| const { id } = this.ctx.params; | ||
| this.ctx.body = await this.service.materialCenter.componentLibrary.delete({ id }); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2023 - present TinyEngine Authors. | ||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * Use of this source code is governed by an MIT-style license. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, | ||||||||||||||||||||||||||||||||||||||||
| * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR | ||||||||||||||||||||||||||||||||||||||||
| * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| import { Controller } from 'egg'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export default class userComponentController extends Controller { | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * @summary 注册组件库 | ||||||||||||||||||||||||||||||||||||||||
| * @router POST /api/componentLibrary/create | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix incorrect route documentation The JSDoc comment doesn't match the actual route defined in the router file. /**
- * @summary 注册组件库
- * @router POST /api/componentLibrary/create
+ * @summary 创建组件库包
+ * @router POST /component/bundle/create
*/📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| async bundleCreate(){ | ||||||||||||||||||||||||||||||||||||||||
| const ctx = this.ctx; | ||||||||||||||||||||||||||||||||||||||||
| const fileStream = await ctx.getFileStream(); | ||||||||||||||||||||||||||||||||||||||||
| this.ctx.body = await this.ctx.service.materialCenter.userComponents.bundleCreate(fileStream); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for file stream operations The method lacks error handling for file upload operations, which can fail for various reasons (invalid file type, size limits, etc.). Add proper error handling to gracefully manage file upload failures: async bundleCreate(){
const ctx = this.ctx;
- const fileStream = await ctx.getFileStream();
- this.ctx.body = await this.ctx.service.materialCenter.userComponents.bundleCreate(fileStream);
+ try {
+ const fileStream = await ctx.getFileStream();
+ this.ctx.body = await this.ctx.service.materialCenter.userComponents.bundleCreate(fileStream);
+ } catch (error) {
+ ctx.logger.error('[UserComponentController] bundleCreate error:', error);
+ ctx.status = error.status || 500;
+ ctx.body = {
+ success: false,
+ message: error.message || 'File upload failed',
+ };
+ }
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,4 +62,13 @@ export default (app: Application) => { | |||||||||||||||||||||||
| subRouter.get('/tasks/status', controller.materialCenter.task.status); | ||||||||||||||||||||||||
| subRouter.get('/tasks/:id', controller.materialCenter.task.findById); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| //组件库 | ||||||||||||||||||||||||
| subRouter.post('/component-library/update/:id',controller.materialCenter.componentLibrary.update); | ||||||||||||||||||||||||
| subRouter.post('/component-library/create',controller.materialCenter.componentLibrary.create); | ||||||||||||||||||||||||
| subRouter.delete('/component-library/delete/:id',controller.materialCenter.componentLibrary.delete); | ||||||||||||||||||||||||
| subRouter.get('/component-library/find',controller.materialCenter.componentLibrary.find); | ||||||||||||||||||||||||
|
Comment on lines
+65
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion API Design: Consider using correct RESTful HTTP methods The component library endpoints follow RESTful naming but are inconsistent with their HTTP methods. For example, the update endpoint uses POST instead of PUT, while delete correctly uses DELETE. Consider adjusting the router methods to align with RESTful conventions: -subRouter.post('/component-library/update/:id',controller.materialCenter.componentLibrary.update);
+subRouter.put('/component-library/update/:id',controller.materialCenter.componentLibrary.update);Also, add spacing after commas for consistency: -subRouter.post('/component-library/update/:id',controller.materialCenter.componentLibrary.update);
+subRouter.put('/component-library/update/:id', controller.materialCenter.componentLibrary.update);📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // 拆分bundle.json | ||||||||||||||||||||||||
| subRouter.post('/component/bundle/create',controller.materialCenter.userComponents.bundleCreate); | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,8 @@ class AppSchema extends SchemaService { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| ['dataSource', this.getSchemaDataSource], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ['i18n', this.getSchemaI18n], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ['componentsTree', this.getSchemaComponentsTree], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ['componentsMap', this.getSchemaComponentsMap] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ['componentsMap', this.getSchemaComponentsMap], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ['packages', this.getPackages] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 获取schema数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -79,10 +80,25 @@ class AppSchema extends SchemaService { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| // 获取应用信息 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private async setMeta(query?): Promise<I_Response> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const metaData: I_Response = await this.service.appCenter.apps.schemaMeta(this.appId, query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const componentLibraryData = await this.service.materialCenter.componentLibrary.list(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.meta = metaData.data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.meta.componentLibrary = componentLibraryData.data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for component library fetch The setMeta method now fetches component library data, but there's no error handling for cases where the fetch operation fails. This could lead to undefined behavior if the service is unavailable. private async setMeta(query?): Promise<I_Response> {
const metaData: I_Response = await this.service.appCenter.apps.schemaMeta(this.appId, query);
- const componentLibraryData = await this.service.materialCenter.componentLibrary.list();
+ let componentLibraryData = { data: [] };
+ try {
+ componentLibraryData = await this.service.materialCenter.componentLibrary.list();
+ } catch (error) {
+ this.ctx.logger.error('Failed to fetch component library data', error);
+ }
this.meta = metaData.data;
this.meta.componentLibrary = componentLibraryData.data;
return metaData;
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return metaData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| private getPackages() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const {componentLibrary} = this.meta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const packages = componentLibrary.map((item) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: item.name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| package: item.packageName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| version: item.version, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| script: item.script, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| css: item.css, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| others: item.others | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.ctx.helper.getResponseData(packages); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+89
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add validation for component library data The getPackages method assumes that componentLibrary always exists and has the expected structure. Add validation to handle cases where the data might be missing or malformed. private getPackages() {
- const {componentLibrary} = this.meta;
+ const componentLibrary = this.meta.componentLibrary || [];
const packages = componentLibrary.map((item) => ({
name: item.name,
package: item.packageName,
version: item.version,
script: item.script,
css: item.css,
others: item.others
}));
return this.ctx.helper.getResponseData(packages);
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 获取元数据 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private getSchemaMeta(): I_Response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const appData = this.meta.app; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2023 - present TinyEngine Authors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Use of this source code is governed by an MIT-style license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { E_Method } from '../../lib/enum'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { I_CreateComponentLibrary } from '../../lib/interface'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as qs from 'querystring'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DataService from '../dataService'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default class ComponentLibrary extends DataService{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async create(param: I_CreateComponentLibrary) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.query({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: 'component-library' , | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: E_Method.Post, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: param | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async find(param){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const query = qs.stringify(param); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.query({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: `component-library?${query}` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve type safety with proper interfaces The Define an interface for the find parameters and specify the return type: +interface FindParams {
+ name?: string;
+ description?: string;
+ [key: string]: any;
+}
-async find(param){
+async find(param: FindParams): Promise<any> {
const query = qs.stringify(param);
return this.query({
url: `component-library?${query}`
});
} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async list() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.query({ url: 'component-library' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async update(param) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { id } = param; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.query({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: `component-library/${id}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: E_Method.Put, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: param | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add type safety to the update method Similar to the +interface UpdateComponentLibrary extends I_CreateComponentLibrary {
+ id: string | number;
+}
-async update(param) {
+async update(param: UpdateComponentLibrary): Promise<any> {
const { id } = param;
return this.query({
url: `component-library/${id}`,
method: E_Method.Put,
data: param
});
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| delete({ id }){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.query({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: `component-library/${id}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: E_Method.Delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use consistent method signatures and add async keyword The -delete({ id }){
+async delete({ id }: { id: string | number }): Promise<any> {
return this.query({
url: `component-library/${id}`,
method: E_Method.Delete
});
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling to service methods None of the methods include error handling, which is essential for robust API operations. Add try-catch blocks to handle potential errors: async create(param: I_CreateComponentLibrary) {
+ try {
return this.query({
url: 'component-library' ,
method: E_Method.Post,
data: param
});
+ } catch (error) {
+ this.ctx.logger.error('[ComponentLibrary] create error:', error);
+ throw error;
+ }
}Apply similar error handling to all other methods in the class. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Follow TypeScript naming conventions
Class names should use PascalCase according to TypeScript conventions.
📝 Committable suggestion