Giải pháp chuyển đổi số trọn gói cho doanh nghiệp Việt

Xây dựng controller cho carcategory.json.js - Xây dựng API backend quản lý Car bằng server nodejs

Xây dựng API backend quản lý Car bằng server nodejs

← Toàn bộ tài liệu


Bước 10.2: Xây dựng controller cho carcategory.json.js

Bài 16/21 Xem dạng sách

Tên file: carcategory.json.js

Nơi lưu file: apps/ecommerce/controllers

Nội dung file:

 

var controllerfrontenditem = require(`${path_root}/lib/mvc/controllers/controllerfrontenditem`);
const factory = require(`${path_root}/lib/Factory.js`);
const common = require(`${path_root}/lib/common`);
const config = common.getConfig();
var model = require(`${path_root}/lib/mvc/models/model`);
const utility = require(`${path_root}/lib/Utilities/Utility.js`);
const redisClient = require('redis').createClient;
const redis = redisClient(6379, 'localhost');
class carcategory_json extends controllerfrontenditem {
async update_total_product_in_sub_carcategory() {
let carcategory_model=model.getInstance("carcategory",1,this.req,this.res,this.next);
await carcategory_model.update_total_product_in_sub_carcategory(this.req,this.res,this.next);
return {
result:"success"
};
}
async update_carcategory() {
let input=factory.getInput(this.req);
let data=input.getData();
let id=input.getString('id',"");
if(id===""){
return {
result:"error",
code:101,
errorMessage: "carcategory must not empty",
data:[]
};
}
let current_model=model.getInstance("carcategory",1,this.req,this.res,this.next);
let item= await current_model.getItem(this.req,this.res,this.next,id);
console.log("item",item);
if(typeof item==="undefined" || item===false || item===null){
return {
result:"error",
code:101,
errorMessage: "carcategory not exists",
data:[]
};
}
item=current_model.save(data);
return {
result:"success",
data:item
};
}
async delete_carcategory() {
let input=factory.getInput(this.req);
let data=input.getData();
let carcategory_id=input.getString('carcategory_id',"");
if(carcategory_id===""){
return {
result:"error",
code:101,
errorMessage: "carcategory id must not empty",
data:[]
};
}
let current_model=model.getInstance("carcategory",1,this.req,this.res,this.next);
let item= await current_model.getItem(this.req,this.res,this.next,carcategory_id);
if(typeof item==="undefined" || item===false || item===null){
return {
result:"error",
code:101,
errorMessage: "carcategory not exists",
data:[]
};
}
current_model.delete(this.req, this.res, this.next,carcategory_id);
return {
result:"success",
data:[]
};
}



}
module.exports = carcategory_json;

Sơ đồ quan hệ các bảng

Table Name: {{table.name}}
Num Name Type
{{field_index+1}}
{{field.name}} {{field.type}}

Hỏi đáp

Gửi với tên {{comment_full_name}}

Chưa có câu hỏi nào cho bài này.

Zalo 0936.006.058 Hotline 0936.006.058