fix:delete profileAvatar
All checks were successful
Build & Deploy on Dev / build (push) Successful in 53s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 53s
This commit is contained in:
parent
e461f43604
commit
633ccd4906
4 changed files with 67 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import { Profile } from "../entities/Profile";
|
|||
import { CreateProfileAvatar, ProfileAvatar } from "../entities/ProfileAvatar";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
@Route("api/v1/org/profile/avatar")
|
||||
@Tags("ProfileAvatar")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -158,12 +159,33 @@ export class ProfileAvatarController extends Controller {
|
|||
"SYS_REGISTRY_OFFICER",
|
||||
_record.profileId,
|
||||
);
|
||||
if (_record.isActive) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: _record.profileId },
|
||||
});
|
||||
if (profile) {
|
||||
profile.avatar = "";
|
||||
profile.avatarName = "";
|
||||
await this.profileRepository.save(profile, { data: req });
|
||||
}
|
||||
}
|
||||
|
||||
await new CallAPI().DeleteFile(req, `${_record?.avatar}/${_record?.avatarName}`);
|
||||
}
|
||||
if (!_record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
await this.avatarRepository.remove(_record, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
// private async deleteFile(avatar: string, avatarName: string) {
|
||||
// const url = process.env.API_URL + `/salary/file/${avatar}/${avatarName}`;
|
||||
// console.log(url);
|
||||
// try {
|
||||
// await http.delete(url);
|
||||
// } catch {}
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import { CreateProfileEmployeeAvatar, ProfileAvatar } from "../entities/ProfileA
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
|
||||
@Route("api/v1/org/profile-employee/avatar")
|
||||
@Tags("ProfileAvatar")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -153,6 +155,18 @@ export class ProfileAvatarEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
_record.profileEmployeeId,
|
||||
);
|
||||
if (_record.isActive) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: _record.profileEmployeeId },
|
||||
});
|
||||
if (profile) {
|
||||
profile.avatar = "";
|
||||
profile.avatarName = "";
|
||||
await this.profileRepository.save(profile, { data: req });
|
||||
}
|
||||
}
|
||||
|
||||
await new CallAPI().DeleteFile(req, `${_record?.avatar}/${_record?.avatarName}`);
|
||||
}
|
||||
if (!_record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { CreateProfileEmployeeAvatar, ProfileAvatar } from "../entities/ProfileA
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
@Route("api/v1/org/profile-temp/avatar")
|
||||
@Tags("ProfileAvatar")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -147,6 +148,19 @@ export class ProfileAvatarEmployeeTempController extends Controller {
|
|||
public async deleteAvatarEmployee(@Path() avatarId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
const _record = await this.avatarRepository.findOneBy({ id: avatarId });
|
||||
if (_record) {
|
||||
if (_record.isActive) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: _record.profileEmployeeId },
|
||||
});
|
||||
if (profile) {
|
||||
profile.avatar = "";
|
||||
profile.avatarName = "";
|
||||
await this.profileRepository.save(profile, { data: req });
|
||||
}
|
||||
}
|
||||
}
|
||||
await new CallAPI().DeleteFile(req, `${_record?.avatar}/${_record?.avatarName}`);
|
||||
if (!_record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,6 +99,23 @@ class CallAPI {
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
//Delete File
|
||||
public async DeleteFile(request: any, @Path() path: any) {
|
||||
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
|
||||
const url = process.env.API_URL + "/salary/file/" + path;
|
||||
try {
|
||||
await axios.delete(url, {
|
||||
headers: {
|
||||
Authorization: `${token}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default CallAPI;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue