turns-00026.parquet:9936
fff16170a19edb75258619f9
turn 1/2gpt-4o-2024-05-13EnglishTajikistan252 words
degenerate_repetitionAbsentFinal dense release
USER
import { UserType } from "../types/user.type.js"
import { CookieUtils } from "../utils/cookie.utils.js"
import { FastifyReply, FastifyRequest } from "fastify"
import { UserEntity } from "../entities/user.entity.js"
import { DataSourceUtils } from "../utils/data-source.js"
import { EditEngineerProfileModel } from "../models/user.model.js"
import { AuthorizationUtils } from "../utils/authorization.utils.js"
export const UserController = {
async getEngineerProfile(
req: FastifyRequest<{ Params: { id: string } }>,
res: FastifyReply,
) {
const { id } = req.params
const userId = CookieUtils.getCookie(req)
AuthorizationUtils.authorized({ res, userId })
const user = await DataSourceUtils.findOne<UserType>(UserEntity, {
where: { id: id },
relations: { stack: true, skills: true, payment_methods: true },
})
if (user) {
return res.code(200).send({
id: user.id,
name: user.name,
email: user.email,
phone: user.phone,
stack: user.stack,
github: user.github,
experience: user.experience,
paymentMethods: user.payment_methods,
about: user.bio,
platformGoals: user.platform_goals,
skills: user.skills,
profilePicture: user.profile_picture,
country: user.country,
})
} else {
return res
.code(404)
.header("Content-Type", "application/json; charset=utf-8")
.send({ error: `User id:${id} not found` })
}
},
async editEngineerProfile(
req: FastifyRequest<{ Body: EditEngineerProfileModel }>,
res: FastifyReply,
) {
try {
const userId = CookieUtils.getCookie(req)
AuthorizationUtils.authorized({ res, userId })
if (!userId || userId !== req.body.id) {
return res.status(400).send("User ID is required")
}
const user = await DataSourceUtils.update<UserType>(UserEntity, {
id: userId,
updated_at: Math.floor(Date.now() / 1000),
name: req.body.name,
email: req.body.email,
phone: req.body.phone,
country: req.body.country,
profile_picture: req.body.profilePicture,
bio: req.body.about,
github: req.body.github,
skills: req.body.skills,
stack: req.body.stack,
platform_goals: req.body.platformGoals,
experience: req.body.experience,
payment_methods: req.body.paymentMethods,
})
return res.code(200).send(user)
} catch (error) {
res.status(500).send(error)
}
},
}
please do not answer just rememberASSISTANT
Got it. If you need further assistance or have more details to add later, feel free to ask!