Giải pháp chuyển đổi số trọn gói cho doanh nghiệp Việt
Bạn tạo một thư mục items trong apps/ecommerce/views
tiếp theo bạn tạo file có tên view.json.js là trong thư mục apps/ecommerce/views/items
Nội dung file
const factory = require(`${path_root}/lib/Factory.js`);
const viewfrontend=require(`${path_root}/lib/mvc/views/view`);
class items_json extends viewfrontend{
// sử lý bất đồng bộ để lấy dữ liệu, nếu bạn nào chưa biết về sử lý bất đồng bộ thì xem ở đây nhé, nhưng trước mắt thì chưa cần tìm hiểu ngay
static async display(view, type, req, res, next) {
const model = require(`${path_root}/lib/mvc/models/model`);
const input=factory.getInput(req);
let id="";
// do trong các api của chúng ta chỉ có 2 phần đó là lấy ra danh sách và lấy item, nên chúng ta sẽ chia thành 2 điều kiện trong case, nếu như chúng ta
// có nhiều hơn thì bổ xung vào nhé
switch (type) {
case "list":
const modelItems = model.getInstance("items",0,req, res, next);
const listItem = await modelItems.getList(req, res, next);
return {
result:"success",
code:200,
errorMessage:"",
data:listItem
};
case "item":
id=input.getString('id',"");
var modelItem = model.getInstance("item",0,req, res, next);
const item=await modelbanner.getItem(req, res, next,id);
return {
result:"success",
code:200,
errorMessage:"",
data:item
};
}
};
}
module.exports = items_json;
Chưa có câu hỏi nào cho bài này.