แก้รูปเก่า false
This commit is contained in:
parent
4a80b30c5b
commit
0524653f4b
1 changed files with 21 additions and 2 deletions
|
|
@ -28,10 +28,19 @@ export class ProfileAvatarController extends Controller {
|
|||
if (!result) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const profile = await this.profileRepository.findOneBy({ id: profileId });
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: profileId },
|
||||
relations: ["profileAvatars"],
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await Promise.all(
|
||||
profile.profileAvatars.map(async (item: any) => {
|
||||
item.isActive = false;
|
||||
await this.avatarRepository.save(item);
|
||||
}),
|
||||
);
|
||||
result.isActive = true;
|
||||
profile.avatar = result.avatar;
|
||||
profile.avatarName = result.avatarName;
|
||||
|
|
@ -40,7 +49,10 @@ export class ProfileAvatarController extends Controller {
|
|||
|
||||
@Post()
|
||||
public async newAvatar(@Request() req: RequestWithUser, @Body() body: CreateProfileAvatar) {
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileId });
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: body.profileId },
|
||||
relations: ["profileAvatars"],
|
||||
});
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
|
|
@ -60,6 +72,13 @@ export class ProfileAvatarController extends Controller {
|
|||
await this.avatarRepository.save(data);
|
||||
let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}`;
|
||||
let fileName = `profile-${data.id}`;
|
||||
|
||||
await Promise.all(
|
||||
profile.profileAvatars.map(async (item: any) => {
|
||||
item.isActive = false;
|
||||
await this.avatarRepository.save(item);
|
||||
}),
|
||||
);
|
||||
data.isActive = true;
|
||||
data.avatar = avatar;
|
||||
data.avatarName = fileName;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue