diff --git a/src/endpoints/management/update_channel.ts b/src/endpoints/management/update_channel.ts new file mode 100644 index 0000000..8383aec --- /dev/null +++ b/src/endpoints/management/update_channel.ts @@ -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; \ No newline at end of file