'use strict'; /* The alliance's shared report folder: share one of your reports, list and read the folder, take one out. */ const { createSharedReportQueries } = require('../sharedReports'); function register(router, services) { const { commands } = services; const folder = createSharedReportQueries(services); const errs = ['unauthorized', 'not_found', 'validation_failed']; router.post('/reports/:id/share', { summary: 'Put one of your reports into your alliance\'s shared folder (needs shareReport; keeps the report for another 14 days)', tag: 'reports', response: { $ref: 'ReportShared' }, errors: errs.concat(['not_in_alliance', 'forbidden', 'world_ended']), }, ({ user, params }) => commands.run('reportShare', { userId: user.id, reportId: params.id })); router.del('/reports/:id/share', { summary: 'Take a report out of the alliance folder (whoever shared it, or leader/officer)', tag: 'reports', response: { $ref: 'ReportShared' }, errors: errs.concat(['forbidden', 'world_ended']), }, ({ user, params }) => commands.run('reportUnshare', { userId: user.id, reportId: params.id })); router.get('/alliances/:id/reports', { summary: 'The alliance\'s shared reports, newest first (cursor: after = id of the last report seen; members only)', tag: 'reports', query: { type: 'object', properties: { after: { type: 'integer', minimum: 1 }, limit: { type: 'integer', minimum: 1, maximum: 100 } } }, response: { $ref: 'SharedReportList' }, errors: errs.concat(['forbidden']), }, ({ user, params, query }) => folder.list(user.id, params.id, query)); router.get('/alliances/:id/reports/:reportId', { summary: 'One shared report with its full data (members only)', tag: 'reports', response: { $ref: 'SharedReportResponse' }, errors: errs.concat(['forbidden']), }, ({ user, params }) => folder.get(user.id, params.id, params.reportId)); } module.exports = { register };