alpha-version-dce-check-in-api
Version:
API for taking attendance and checking people in.
53 lines (44 loc) • 1.26 kB
text/typescript
// Import dce-reactkit
import { genRouteHandler } from '../../../../dce-reactkit';
// Import types
import CanvasUser from '../../../types/CanvasUser';
import Router from '../../../types/Router';
// Import shared types
import CanvasAPI from '../../../shared/types/CanvasAPI';
import User from '../../../shared/types/User';
// Static helpers
const canvasUserToUser = (canvasUser: CanvasUser): User => {
const {
id: userId,
first_name: userFirstName,
last_name: userLastName,
} = canvasUser;
return {
userId,
userFirstName,
userLastName,
};
};
/**
* Endpoint for retrieving the current Canvas course roster (list of students).
* @author Benedikt Arnarsson
* @param router the router that we are adding the endpoint to.
* @param getCanvasAPI function to retrieve API for interacting with Canvas.
*/
const addGetRosterRoute = (
router: Router,
getCanvasAPI: () => CanvasAPI,
) => {
router.get(
'/students',
genRouteHandler({
handler: async () => {
const canvas = getCanvasAPI();
const canvasUserList = await canvas.course.listStudents();
const userList = canvasUserList.map(canvasUserToUser);
return userList;
},
}),
);
};
export default addGetRosterRoute;