MC/website/node/honour-route.mjs
2026-11-27 23:43:05 +00:00

15 lines
717 B
JavaScript

import {identity} from './auth.mjs';
import {honourAction} from './honours.mjs';
// The Order has its own grant authority; rank-administration permission is unrelated.
export function createHonourRoute(db,origin,{authenticate=identity,action=honourAction}={}){
return async request=>{
const headers={'Cache-Control':'no-store'};
if(!['GET','POST'].includes(request.method))return Response.json({message:'Method not allowed.'},{status:405,headers});
const actor=await authenticate(request,db);
if(!actor)return Response.json({message:'Sign in first.'},{status:401,headers});
const response=await action(db,actor,request,origin);
response.headers.set('Cache-Control','no-store');
return response;
};
}