diff --git a/src/resources/activity/activityDocs.yml b/src/resources/activity/activityDocs.yml index 743d3b2b7b6ee96eaf3c2350c2019bd9276aa8bb..d16d409a2ff3ff47b022edc04ea1bb623d648475 100644 --- a/src/resources/activity/activityDocs.yml +++ b/src/resources/activity/activityDocs.yml @@ -107,7 +107,7 @@ components: items: type: string description: cuid of each attendance - comment: + comments: type: array items: type: string diff --git a/src/resources/attendance/__tests__/attendanceFuncTest.js b/src/resources/attendance/__tests__/attendanceFuncTest.js index f4f4cdd321448d9ca6901dde7b8af6901c627081..d0858f91e9954b362441ab15c7a38e4eed2f25fd 100644 --- a/src/resources/attendance/__tests__/attendanceFuncTest.js +++ b/src/resources/attendance/__tests__/attendanceFuncTest.js @@ -42,7 +42,9 @@ describe('/group "Mentor" Functionality', () => { // GET One test(`GET returns with allowed keys`, async () => { const newAttendance = await Attendance.create(fakeAttendanceJson) - let response = await authSession.get(`${endpointUrl}/${newAttendance._id}`) + let response = await authSession.get( + `${endpointUrl}/id/${newAttendance._id}` + ) expect(response.statusCode).toBe(200) validateKeys(response.body.data, defaultKeys) }) @@ -71,7 +73,7 @@ describe('/group "Mentor" Functionality', () => { test(`Delete group returns with allowed keys`, async () => { const newAttendance = await Attendance.create(fakeAttendanceJson) let response = await authSession.delete( - `${endpointUrl}/${newAttendance._id}` + `${endpointUrl}/id/${newAttendance._id}` ) expect(response.statusCode).toBe(200) validateKeys(response.body.data, defaultKeys) @@ -80,7 +82,7 @@ describe('/group "Mentor" Functionality', () => { test(`Update group returns with allowed keys`, async () => { const newAttendance = await Attendance.create(fakeAttendanceJson) let response = await authSession - .put(`${endpointUrl}/${newAttendance._id}`) + .put(`${endpointUrl}/id/${newAttendance._id}`) .send({ state: 'present', }) diff --git a/src/resources/attendance/__tests__/attendancePermTest.js b/src/resources/attendance/__tests__/attendancePermTest.js index 4366a8dced12ccf3ab617e90e63bc3b3d7aa0453..9b9b81c222f35c0fc7a82021de22eb2498dce1cf 100644 --- a/src/resources/attendance/__tests__/attendancePermTest.js +++ b/src/resources/attendance/__tests__/attendancePermTest.js @@ -11,13 +11,28 @@ const fakeAttendanceJson = { } describe('/attendance Permission tests', () => { + crudPermTest( + app, + endpointUrl + '/id', + Attendance, + 'attendance', + fakeAttendanceJson, + [false, false, true, true, true], + [ + // [role, create, readAll, readOne, update, delete] + ['none', false, false, false, false, false], + ['normal', false, false, false, false, false], + ['accepted', false, false, false, false, false], + ['mentor', true, true, true, true, true], + ] + ) crudPermTest( app, endpointUrl, Attendance, 'attendance', fakeAttendanceJson, - [true, true, true, true, true], + [true, true, false, false, false], [ // [role, create, readAll, readOne, update, delete] ['none', false, false, false, false, false], diff --git a/src/resources/attendance/attendanceDocs.yml b/src/resources/attendance/attendanceDocs.yml new file mode 100644 index 0000000000000000000000000000000000000000..415038429fd2ad78a06de5a416dfeaca35590352 --- /dev/null +++ b/src/resources/attendance/attendanceDocs.yml @@ -0,0 +1,113 @@ +openapi: '3.0.2' +info: + title: 'Attendance Endpoint' + version: '1.0' + +paths: + /attendance: + get: + tags: + - 'Attendance' + summary: 'Get a List of attendances' + description: 'Have to be mentor for this.' + operationId: 'getAllAttendance' + responses: + '200': + description: OK + content: + application/json: + schema: + type: 'array' + items: + $ref: '#/components/schemas/Attendance' + post: + tags: + - 'Attendance' + summary: 'Create an attendance' + description: 'Have to be mentor for this.' + operationId: 'createAttendance' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Attendance' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Attendance' + /attendance/id/{id}: + get: + tags: + - 'Attendance' + summary: 'Get an attendance by ID' + description: 'Have to be mentor for this.' + operationId: 'getAttendance' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Attendance' + put: + tags: + - 'Attendance' + summary: 'Update an attendance by ID' + description: 'Only mentors can update an attendance.' + operationId: 'updateOneAttendance' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Attendance' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Attendance' + delete: + tags: + - 'Attendance' + summary: 'Delete an attendance by ID' + description: 'Only mentors can delete an attendance.' + operationId: 'deleteAttendance' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Attendance' + +components: + schemas: + Attendance: + type: object + properties: + activity: + type: string + description: cuid of each attendance + user: + type: string + description: schacc of the user + state: + type: string + enum: + - absent + - present + - cantcome + default: absent + comments: + type: array + items: + type: string + description: cuid of each comment + required: + - activity + - user + - state diff --git a/src/resources/attendance/attendanceRouter.js b/src/resources/attendance/attendanceRouter.js index db5d6ae2749eb6be5462bfb49de5677a075f132e..aa2468a81b646a4029ccb579b3b6cec73e932e07 100644 --- a/src/resources/attendance/attendanceRouter.js +++ b/src/resources/attendance/attendanceRouter.js @@ -4,15 +4,15 @@ const { isLoggedIn, isMentor } = require('../../middlewares/auth') const router = Router() -// /api/item +// /api/v1/attendance/ router .route('/') .get(isLoggedIn, isMentor, controllers.getMany) .post(isLoggedIn, isMentor, controllers.createOne) -// /api/item/:id +// /api/v1/attendance/id/:id router - .route('/:id') + .route('/id/:id') .get(isLoggedIn, isMentor, controllers.getOne) .put(isLoggedIn, isMentor, controllers.updateOne) .delete(isLoggedIn, isMentor, controllers.removeOne)