This commit is contained in:
AdisakKanthawilang 2024-10-04 18:12:23 +07:00
parent b9bc5b1298
commit cb1eb5a68e
8 changed files with 92 additions and 56 deletions

View file

@ -7,6 +7,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { CreateProfileAvatar, ProfileAvatar } from "../entities/ProfileAvatar";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/avatar")
@Tags("ProfileAvatar")
@Security("bearerAuth")
@ -121,14 +122,15 @@ export class ProfileAvatarController extends Controller {
await this.avatarRepository.save(data);
let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}`;
let fileName = `profile-${data.id}`;
const before = null;
data.isActive = true;
data.avatar = avatar;
data.avatarName = fileName;
await this.avatarRepository.save(data);
await this.avatarRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
profile.avatar = avatar;
profile.avatarName = fileName;
await this.profileRepository.save(profile);
await this.profileRepository.save(profile, { data: req });
return new HttpSuccess({ avatar: avatar, avatarName: fileName });
}
@ -143,11 +145,11 @@ export class ProfileAvatarController extends Controller {
_record.profileId,
);
}
const result = await this.avatarRepository.delete({ id: avatarId });
if (result.affected == undefined || result.affected <= 0) {
if (!_record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
await this.avatarRepository.remove(_record, {data: req});
return new HttpSuccess();
}