Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

import { UserType } from "../types/user.type.js" import { CookieUtils } from…

  1. 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 remember

  2. Assistant

    Got it. If you need further assistance or have more details to add later, feel free to ask!

  3. User

    import { ChangeEvent, CSSProperties, useState } from "react" import styles from "./upload-card.module.css" import { Icon } from "../icon/icon.component.tsx" import classNames from "classnames"

    export function UploadCard({ photo, className, style, wrapperStyle, }: { photo: string | null className?: string style?: CSSProperties wrapperStyle?: CSSProperties }) { // --------------------------------------------------------------------------- // variables // ---------------------------------------------------------------------------

    const [selectedImage, setSelectedImage] = useState<string | null>(null)

    // --------------------------------------------------------------------------- // functions // ---------------------------------------------------------------------------

    function handleImageChange(event: ChangeEvent) { if (event.target.files && event.target.files[0]) { const reader = new FileReader() reader.onload = (e) => { if (e.target?.result) { setSelectedImage(e.target.result as string) } } reader.readAsDataURL(event.target.files[0]) } }

    // --------------------------------------------------------------------------- return ( <div style={wrapperStyle} className={classNames(styles.container, className)} > <img style={style} src={selectedImage || photo || ""} className={styles.profileImg} alt="img" /> <Icon name={"fa-solid fa-up-from-line"} size="1.6" className={styles.icon} /> Upload photo <input type="file" id="files" style={{ visibility: "hidden" }} onChange={handleImageChange} /> ) } please do not answer just remember

  4. Assistant

    Understood. If you need further assistance or more information later, feel free to ask!