อัพรูป
This commit is contained in:
parent
6010cc662c
commit
3ea5ec3486
3 changed files with 77 additions and 17 deletions
|
|
@ -44,6 +44,8 @@ export class ProfileAvatarController extends Controller {
|
|||
result.isActive = true;
|
||||
profile.avatar = result.avatar;
|
||||
profile.avatarName = result.avatarName;
|
||||
await this.avatarRepository.save(result);
|
||||
await this.profileRepository.save(profile);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +53,6 @@ export class ProfileAvatarController extends Controller {
|
|||
public async newAvatar(@Request() req: RequestWithUser, @Body() body: CreateProfileAvatar) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: body.profileId },
|
||||
relations: ["profileAvatars"],
|
||||
});
|
||||
|
||||
if (!profile) {
|
||||
|
|
@ -69,16 +70,10 @@ export class ProfileAvatarController extends Controller {
|
|||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
// await this.avatarRepository.save(data);
|
||||
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;
|
||||
|
|
@ -87,6 +82,21 @@ export class ProfileAvatarController extends Controller {
|
|||
profile.avatarName = fileName;
|
||||
await this.profileRepository.save(profile);
|
||||
|
||||
const _profile = await this.profileRepository.findOne({
|
||||
where: { id: body.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);
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess({ avatar: avatar, avatarName: fileName });
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue