Nest.js 问题, 1:树形数据存修改如何操作。2: typeorm 异常如何处理

查看 20|回复 0
作者:LandCruiser   
  • 问题 1:树形数据如何修改

    {
            "create_time": "2023-08-21T08:27:50.146Z",
            "update_time": "2023-08-24T07:54:34.000Z",
            "id": 1,
            "name": "部门 1",
            "code": "1111",
            "down_dep": [
                {
                    "create_time": "2023-08-21T08:27:50.146Z",
                    "update_time": "2023-08-24T07:55:25.000Z",
                    "id": 22,
                    "name": "部门 2",
                    "code": "100"
                }
            ],
            "up_dep": null
        },
       
    这种接口的数据怎么修改?
    还有一个问题就是 DTO 中没有 create_time ,update_time 两个字段,修改时传入就会报错。
  • 第二个问题,typeorm 异常如何处理

       at Query.onResult (C:\pm-server\src\driver\mysql\MysqlQueryRunner.ts:222:33)
       at Query.execute (C:\pm-server\node_modules\mysql2\lib\commands\command.js:36:14)
       at PoolConnection.handlePacket (C:\pm-server\node_modules\mysql2\lib\connection.js:478:34)
       at PacketParser.onPacket (C:\pm-server\node_modules\mysql2\lib\connection.js:97:12)
       at PacketParser.executeStart (C:\pm-server\node_modules\mysql2\lib\packet_parser.js:75:16)
       at Socket. (C:\pm-server\node_modules\mysql2\lib\connection.js:104:25)
       at Socket.emit (node:events:513:28)
       at addChunk (node:internal/streams/readable:324:12)
       at readableAddChunk (node:internal/streams/readable:297:9)
       at Socket.Readable.push (node:internal/streams/readable:234:10) {
    query: 'INSERT INTO `dept`(`create_time`, `update_time`, `id`, `name`, `code`, `upDepId`) VALUES (DEFAULT, DEFAULT, DEFAULT, ?, ?, DEFAULT)',
    parameters: [ '456456', '1111' ],
    driverError: Error: Duplicate entry '456456' for key 'IDX_5eb4a4c9f25934f105299edffd'
         at Packet.asError (C:\pm-server\node_modules\mysql2\lib\packets\packet.js:728:17)
         at Query.execute (C:\pm-server\node_modules\mysql2\lib\commands\command.js:29:26)
         at PoolConnection.handlePacket (C:\pm-server\node_modules\mysql2\lib\connection.js:478:34)
         at PacketParser.onPacket (C:\pm-server\node_modules\mysql2\lib\connection.js:97:12)
         at PacketParser.executeStart (C:\pm-server\node_modules\mysql2\lib\packet_parser.js:75:16)
         at Socket. (C:\pm-server\node_modules\mysql2\lib\connection.js:104:25)
         at Socket.emit (node:events:513:28)
         at addChunk (node:internal/streams/readable:324:12)
         at readableAddChunk (node:internal/streams/readable:297:9)
         at Socket.Readable.push (node:internal/streams/readable:234:10) {
       code: 'ER_DUP_ENTRY',
       errno: 1062,
       sqlState: '23000',
       sqlMessage: "Duplicate entry '456456' for key 'IDX_5eb4a4c9f25934f105299edffd'",
       sql: "INSERT INTO `dept`(`create_time`, `update_time`, `id`, `name`, `code`, `upDepId`) VALUES (DEFAULT, DEFAULT, DEFAULT, '456456', '1111', DEFAULT)"
    },
    code: 'ER_DUP_ENTRY',
    errno: 1062,
    sqlState: '23000',
    sqlMessage: "Duplicate entry '456456' for key 'IDX_5eb4a4c9f25934f105299edffd'",
    sql: "INSERT INTO `dept`(`create_time`, `update_time`, `id`, `name`, `code`, `upDepId`) VALUES (DEFAULT, DEFAULT, DEFAULT, '456456', '1111', DEFAULT)"
    }```
    值重复异常如何处理?自己写正则吗?
  • 您需要登录后才可以回帖 登录 | 立即注册

    返回顶部