简体   繁体   中英

postgres update query is not working in node,js

I have an update query which seems to be not working. The underlying database used is postgres. Could you please check why it is not working? I have included my api and schema. Thanks in advance

exports.patch_meetup = async (req, res) => {
    const findOneQuery = 'SELECT * FROM meetups WHERE id=$1';
    const updateOneQuery = `UPDATE meetups
      SET topic=$1, location=$2, body=$3, happeningOn=$4, Tags=$5, meetupImage=$6, createdOn=$7
      WHERE id=$8 returning *`;
    try {
        const {
            rows
        } = await db.query(findOneQuery, [req.params.id]);
        if (!rows[0]) {
            return res.status(404).json({
                'message': 'meetup not found'
            });
        }
        const values = [
            req.body.topic,
            req.body.location,
            req.body.body,
            req.body.happeningOn,
            req.body.Tags,
            req.file.path,
            moment(new Date()),
            req.params.id
        ];
        const response = await db.query(updateOneQuery, values);
        return res.status(200).json(response.rows[0]);
    } catch (err) {
        return res.status(400).send(err);
    }
};`

Here is my model

const meetupTable = CREATE TABLE IF NOT EXISTS
        meetups(
            id UUID PRIMARY KEY,
            topic VARCHAR(128) NOT NULL,
            location VARCHAR(128) NOT NULL,
            body TEXT NOT NULL,
            happeningOn TIMESTAMPTZ NOT NULL,
            Tags TEXT[] NOT NULL,
            meetupImage bytea,
            createdOn TIMESTAMPTZ DEFAULT Now()
        )

我不确定问题可能是什么,但一个可能是你忘记将 multer 中间件添加到 API 端点,另一个就像我在评论中提到的那样,你不应该传递 moment 对象,而应该传递 date 对象作为这是。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM