123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- // 添加账本
- import express from "express";
- const router = express.Router();
- import {
- record_insert,
- isType,
- type_insert,
- getRecordInfoById
- } from "#db";
- import {shanghaiTime} from '#utils'
- // middleware that is specific to this router
- router.use(function timeLog(req, res, next) {
- console.log("Time: ", Date.now());
- next();
- });
- // 添加单个账单记录
- router.post("/", async function (req, res) {
- const {
- book_id = "",
- total_fee = 0,
- type = "",
- remark = "",
- files = [],
- userInfo = {},
- } = req.body;
- // type 是否存在重复项,有就返回id,没有就新增 再返回id
- const isAddType = await isType({
- book_id,
- user_id: userInfo.user_id,
- type,
- });
- let typeInfo = {};
- if (!isAddType) {
- await type_insert({
- book_id,
- user_id: userInfo.user_id,
- type,
- create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- });
- typeInfo = await isType({
- book_id,
- user_id: userInfo.user_id,
- type,
- });
- } else {
- typeInfo = { ...isAddType };
- }
- console.log(51, {
- book_id,
- type_id: typeInfo.id,
- author_id: userInfo.user_id,
- total_fee,
- remark,
- create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- })
- const insertId = await record_insert({
- book_id,
- type_id: typeInfo.id,
- author_id: userInfo.user_id,
- total_fee,
- remark,
- create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- });
- res.json({
- code: 200,
- data: {
- record_id: insertId
- }
- });
- });
- // define the home page route
- router.get("/:record_id", async function (req, res) {
- const record_id = req.params.record_id; // 获取 fileId 参数
- const recordInfo = await getRecordInfoById(record_id)
- res.json({
- code: 200,
- data: recordInfo
- });
- });
- // define the about route
- router.get("/about", function (req, res) {
- res.send("About record");
- });
- export default router;
|