Create the update channel endpoint
This commit is contained in:
parent
fc8c62f3ea
commit
7614b9560f
1 changed files with 31 additions and 0 deletions
31
src/endpoints/management/update_channel.ts
Normal file
31
src/endpoints/management/update_channel.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { ServerRoute } from "@hapi/hapi";
|
||||
import boom from "@hapi/boom";
|
||||
import { db } from "@/main";
|
||||
import Joi from "joi";
|
||||
|
||||
const data: ServerRoute = {
|
||||
method: `PATCH`, path: `/manage/{channel}`,
|
||||
options: {
|
||||
validate: {
|
||||
params: Joi.object({
|
||||
channel: Joi.string().alphanum(),
|
||||
}),
|
||||
payload: Joi.object({
|
||||
default_unlurk: Joi.string().min(1),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request, h) {
|
||||
const { channel } = request.params;
|
||||
const { default_unlurk } = request.payload as any;
|
||||
|
||||
if (!db[channel]) {
|
||||
throw boom.notFound(`Invalid channel`);
|
||||
};
|
||||
|
||||
db[channel].unlurk_default = default_unlurk;
|
||||
|
||||
return h.response().code(200);
|
||||
},
|
||||
};
|
||||
export default data;
|
||||
Loading…
Add table
Add a link
Reference in a new issue