nfp_sites/old/staff/routes.mjs

45 lines
1 KiB
JavaScript
Raw Normal View History

import Staff from './model.mjs'
import * as security from './security.mjs'
export default class StaffRoutes {
constructor(opts = {}) {
Object.assign(this, {
Staff: opts.Staff || Staff,
security: opts.security || security,
})
}
2021-01-04 10:55:22 +00:00
/** GET: /api/staff */
async getAllStaff(ctx) {
2021-02-05 11:50:01 +00:00
ctx.body = await this.Staff.getAll(ctx, null, [])
}
2021-01-04 10:55:22 +00:00
/** GET: /api/staff/:id */
async getSingleStaff(ctx) {
ctx.body = await this.Staff.getSingle(ctx.params.id, [], true, ctx)
}
2021-01-04 10:55:22 +00:00
/** POST: /api/staff */
async createStaff(ctx) {
await this.security.validUpdate(ctx)
ctx.body = await this.Staff.create(ctx.request.body)
}
2021-01-04 10:55:22 +00:00
/** PUT: /api/staff/:id */
async updateStaff(ctx) {
await this.security.validUpdate(ctx)
2021-02-05 11:50:01 +00:00
let staff = await this.Staff.updateSingle(ctx, ctx.params.id, ctx.request.body)
2021-02-05 11:50:01 +00:00
ctx.body = staff
}
2021-01-04 10:55:22 +00:00
/** DELETE: /api/staff/:id */
async removeStaff(ctx) {
2021-02-05 11:50:01 +00:00
await this.Staff.updateSingle(ctx, ctx.params.id, { is_deleted: true })
ctx.status = 204
}
}