All files / resources/api/v2 aladtec.ts

0% Statements 0/28
0% Branches 0/1
0% Functions 0/1
0% Lines 0/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                                                                                     
import {
  LambdaApiFunction,
  handleResourceApi
} from './_base';
 
import {
  api401Body, api403Body
} from '@/types/api/_shared';
import { GetAladtecUsersApi } from '@/types/api/aladtec';
import { getShiftData } from '@/utils/backend/shiftData';
import { getLogger } from '@/utils/common/logger';
 
const logger = getLogger('resources/api/v2/aladtec');
 
const GET: LambdaApiFunction<GetAladtecUsersApi> = async function (event, user, userPerms) {
  logger.trace('GET', ...arguments);
 
  // Authorize the user
  if (user === null) {
    return [
      401,
      api401Body,
    ];
  }
  if (!userPerms.isDistrictAdmin) {
    return [
      403,
      api403Body,
    ];
  }
 
  const shiftData = await getShiftData();
 
  return [
    200,
    shiftData.people,
  ];
};
 
export const main = handleResourceApi.bind(null, {
  GET,
});