You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

46 lines
1.1 KiB

import { Color } from "@/model/Color";
import { gFail, gSuccess } from "@/util";
import Joi from "joi";
import { auth, method, route, validate } from "@noderun/hapi-router";
export default class {
index(request,h){
return h.view('views/color.pug')
}
@method("POST")
@route("/add")
@validate({
payload: Joi.object({
color: Joi.string().required(),
title: Joi.string(),
describe: Joi.string(),
}),
})
async add(request, h) {
let { color, title, describe } = request.payload || {};
try {
await Color.create({ color, title, describe });
return gSuccess("success");
} catch (error) {
request.log("error", error);
return gFail(null, "添加颜色失败");
}
}
@method("GET")
@route("/all_color")
async getAll(request, h) {
try {
let allColors = <any>await Color.findAll();
if (allColors == null) {
return gFail(null, "不存在颜色");
}
return gSuccess(allColors, "success");
} catch (error) {
request.log("error", error);
return gFail(null, "获取颜色失败");
}
}
}