forked from Yara724/api
Remove profile plate management and restrict personal profile updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { UserDbService } from "src/users/entities/db-service/user.db.service";
|
||||
import { ProfileUserRs } from "./dto/user/profile.dto";
|
||||
|
||||
@@ -8,10 +8,18 @@ export class ProfileService {
|
||||
|
||||
async getProfileDetail(username: string) {
|
||||
const userDetail = await this.userDbService.findOne({ username });
|
||||
return new ProfileUserRs(userDetail, {});
|
||||
return new ProfileUserRs(userDetail);
|
||||
}
|
||||
|
||||
async updateProfile(username: string, update) {
|
||||
return await this.userDbService.findOneAndUpdate({ username }, update);
|
||||
const allowedFields = ["birthDay", "gender", "city", "state", "address"];
|
||||
if (Object.keys(update).some((field) => !allowedFields.includes(field))) {
|
||||
throw new BadRequestException("Only personal profile fields can be updated");
|
||||
}
|
||||
const userDetail = await this.userDbService.findOneAndUpdate(
|
||||
{ username },
|
||||
{ $set: update },
|
||||
);
|
||||
return new ProfileUserRs(userDetail);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user