update hard delete service user

This commit is contained in:
2024-12-13 09:47:52 +07:00
parent 2b803386fa
commit cdf8d4c07d
6 changed files with 30 additions and 10 deletions

View File

@ -30,7 +30,7 @@
"auth": { "auth": {
"refresh_token_lifetime_day": 30, "refresh_token_lifetime_day": 30,
"access_token_lifetime": 86400, "access_token_lifetime": 86400,
"reset_password_url": "https://bri-dev.shiblysolution.id/reset-password/" "reset_password_url": "https://bri-dev.shiblysolution.id/auth/reset-password/"
}, },
"service": { "service": {
"notification": "http://127.0.0.1:4008/" "notification": "http://127.0.0.1:4008/"

View File

@ -30,7 +30,7 @@
"auth": { "auth": {
"refresh_token_lifetime_day": 30, "refresh_token_lifetime_day": 30,
"access_token_lifetime": 86400, "access_token_lifetime": 86400,
"reset_password_url": "https://bri-dev.shiblysolution.id/reset-password/" "reset_password_url": "https://bri-dev.shiblysolution.id/auth/reset-password/"
}, },
"service": { "service": {
"notification": "http://127.0.0.1:4008/" "notification": "http://127.0.0.1:4008/"

View File

@ -459,17 +459,24 @@ export class UserController {
required: true, required: true,
type: 'string' type: 'string'
} }
#swagger.parameters['hard'] = {
in: 'path',
description: 'Is Hard Delete',
required: false,
type: 'boolean'
}
*/ */
try { try {
const schema = Joi.object().keys({ const schema = Joi.object().keys({
id: Joi.string().uuid().required().label('ID') id: Joi.string().uuid().required().label('ID'),
hard: Joi.bool().optional().allow('').label('Is hard delete?')
}); });
const param: User = await schema.validateAsync(req.params); const param: { id: string, hard: boolean } = await schema.validateAsync(req.params);
const userRepository = OrmHelper.DB.getRepository(User); const userRepository = OrmHelper.DB.getRepository(User);
const affected = (await userRepository.softDelete({ id: param.id })).affected; const affected = (!param.hard ? await userRepository.softDelete({ id: param.id }) : await userRepository.delete({ id: param.id })).affected;
if (affected > 0) { if (affected > 0) {
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_delete, {}); return ReturnHelper.successResponseAny(res, 200, Language.lang.success_delete, {});

View File

@ -350,13 +350,20 @@ export class UserRoleController {
required: true, required: true,
type: 'string' type: 'string'
} }
#swagger.parameters['hard'] = {
in: 'path',
description: 'Is Hard Delete',
required: false,
type: 'boolean'
}
*/ */
try { try {
const schema = Joi.object().keys({ const schema = Joi.object().keys({
id: Joi.string().uuid().required().label('ID') id: Joi.string().uuid().required().label('ID'),
hard: Joi.bool().optional().allow('').label('Is hard delete?')
}); });
const param: UserRole = await schema.validateAsync(req.params); const param: { id: string, hard: boolean } = await schema.validateAsync(req.params);
const repo_role = OrmHelper.DB.getRepository(UserRole); const repo_role = OrmHelper.DB.getRepository(UserRole);
const repo_user = OrmHelper.DB.getRepository(User); const repo_user = OrmHelper.DB.getRepository(User);
@ -364,7 +371,7 @@ export class UserRoleController {
const check_used = await repo_user.findOneBy({ id_role: param.id }) const check_used = await repo_user.findOneBy({ id_role: param.id })
if (check_used == null) { if (check_used == null) {
const affected = (await repo_role.softDelete({ id: param.id })).affected; const affected = (!param.hard ? await repo_role.softDelete({ id: param.id }) : await repo_role.delete({ id: param.id })).affected;
if (affected > 0) { if (affected > 0) {
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_delete, {}); return ReturnHelper.successResponseAny(res, 200, Language.lang.success_delete, {});

View File

@ -20,7 +20,7 @@ export class RoutePrivate {
app.put('/api/user/update_profile', UserController.updateProfile) app.put('/api/user/update_profile', UserController.updateProfile)
app.put('/api/user/update_password', UserController.updatePassword) app.put('/api/user/update_password', UserController.updatePassword)
app.get('/api/user/detail/:id', UserController.detail) app.get('/api/user/detail/:id', UserController.detail)
app.delete('/api/user/delete/:id', UserController.delete) app.delete('/api/user/delete/:id/:hard', UserController.delete)
app.put('/api/user/restore/:id', UserController.restore) app.put('/api/user/restore/:id', UserController.restore)
app.get('/api/user_role/list', UserRoleController.list) app.get('/api/user_role/list', UserRoleController.list)
@ -28,7 +28,7 @@ export class RoutePrivate {
// app.get('/api/user_role/role', UserRoleController.role) // app.get('/api/user_role/role', UserRoleController.role)
app.post('/api/user_role/create', UserRoleController.create) app.post('/api/user_role/create', UserRoleController.create)
app.put('/api/user_role/update/:id', UserRoleController.update) app.put('/api/user_role/update/:id', UserRoleController.update)
app.delete('/api/user_role/delete/:id', UserRoleController.delete) app.delete('/api/user_role/delete/:id/:hard', UserRoleController.delete)
app.put('/api/user_role/restore/:id', UserRoleController.restore) app.put('/api/user_role/restore/:id', UserRoleController.restore)
app.get('/api/user_activity/list', UserActivityController.list) app.get('/api/user_activity/list', UserActivityController.list)

View File

@ -20,11 +20,17 @@ const doc = {
$password: "123456" $password: "123456"
}, },
user: { user: {
$nik: "123456789",
$email: "admin@gmail.com", $email: "admin@gmail.com",
$username: "admin", $username: "admin",
$password: "123456", $password: "123456",
$retype_password: "123456", $retype_password: "123456",
$name: "Administrator", $name: "Administrator",
$phone: "08123456789",
$jabatan: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
$organisasi: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
$divisi: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
$unit: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
$id_role: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8", $id_role: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
$status: "Y" $status: "Y"
}, },