Skip to content

Commit afb2fa8

Browse files
Admin - release Coaster
1 parent 5adf623 commit afb2fa8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/controller/Admin.controller.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/* Import database configuration */
44
import { connect } from '../config/config';
5+
import { COASTERS_NOT_FOUND, COASTERS_NOT_LINKED, COASTER_ACC_REVOKED } from '../config/messages';
56

67
/* Import entities */
78
import { Coasters } from '../entity/Coasters';
@@ -58,4 +59,22 @@ exports.getCoaster = (coasterId: string) => {
5859
}
5960
});
6061
}
62+
63+
/** Remove user from coaster */
64+
exports.releaseCoaster = (coasterId) => {
65+
return new Promise(async (resolve, reject) => {
66+
const connection = await connect();
67+
const repo = connection.getRepository(Coasters);
68+
69+
let [coaster] = await repo.find({ where: { coasterId } });
70+
if (!coaster) return reject(COASTERS_NOT_FOUND);
71+
72+
/** Remove userId and set active to false */
73+
coaster.userId = null;
74+
coaster.active = false;
75+
76+
await repo.save(coaster);
77+
78+
resolve(COASTER_ACC_REVOKED)
79+
})
6180
}

src/routes/Admin.route.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@ router.get('/coasters/:coasterId', async (req: Request, res: Response) => {
6464
}
6565
});
6666

67+
router.delete('/coasters/:coasterId', async (req: Request, res: Response) => {
68+
const { coasterId } = req.params;
69+
try {
70+
globalThis.Logger.log('info', `[${NAMESPACE}] Releasing Coaster `, { ...globalThis.LoggingParams, coasterId })
71+
res.send(await Admin.releaseCoaster(coasterId));
72+
} catch(error) {
73+
globalThis.Logger.log('error', `[${NAMESPACE}] Could not release Coaster `, { ...globalThis.LoggingParams, coasterId, error })
74+
res.send(error);
75+
}
76+
})
77+
6778
module.exports = router;

0 commit comments

Comments
 (0)