@opengis/admin
Version:
This project Softpro Admin
19 lines (14 loc) • 922 B
JavaScript
import { pgClients } from "@opengis/fastify-table/utils.js";
export default async function userEdit(req, reply) {
const {
pg = pgClients.client, body = {}, user = {}, params = {}
} = req
if (!params?.id) return reply.code(400).send({ status: 400, message: 'User id is empty' });
const { id } = params;
if (user?.uid !== id) return reply.code(403).send({ status: 403, message: 'Invalid user id' });
if (!body) return reply.code(400).send({ status: 400, message: 'body id is empty' });
const { sur_name, user_name, father_name, email, phone, avatar } = body
const updateSql = 'update admin.users set sur_name=$2,user_name=$3,father_name=$4,email=$5,phone=$6,avatar=$7 where uid =$1';
await pg.query(updateSql, [id, sur_name, user_name, father_name, email, phone, avatar]);
return reply.code(200).send({ status: 200, message: 'Updated successfully!' })
}