2019-11-14 07:56:03 -05:00
|
|
|
import express from 'express';
|
|
|
|
|
2020-01-31 13:02:24 -05:00
|
|
|
import { ApiParamError, ApiUserError } from '../errors/api';
|
|
|
|
import { ArgumentError } from '../errors/general';
|
2020-01-31 10:45:12 -05:00
|
|
|
import { checkRegexParam, parsePositiveIntParam, processParam } from '../parameters';
|
2019-11-14 07:56:03 -05:00
|
|
|
import asyncController from "../routes/asyncController";
|
|
|
|
import * as editHistoryService from '../services/editHistory';
|
|
|
|
|
|
|
|
const getGlobalEditHistory = asyncController(async (req: express.Request, res: express.Response) => {
|
2020-01-31 10:45:12 -05:00
|
|
|
|
|
|
|
const revisionIdRegex = /^[1-9]\d*$/;
|
|
|
|
const afterId: string = processParam(req.query, 'after_id', x => checkRegexParam(x, revisionIdRegex));
|
|
|
|
const beforeId: string = processParam(req.query, 'before_id', x => checkRegexParam(x, revisionIdRegex));
|
|
|
|
const count: number = processParam(req.query, 'count', parsePositiveIntParam);
|
|
|
|
|
|
|
|
if(afterId != undefined && beforeId != undefined) {
|
2020-01-31 13:02:24 -05:00
|
|
|
throw new ApiUserError('Cannot specify both after_id and before_id parameters');
|
2020-01-31 10:45:12 -05:00
|
|
|
}
|
|
|
|
|
2019-11-14 07:56:03 -05:00
|
|
|
try {
|
2020-01-31 10:45:12 -05:00
|
|
|
const result = await editHistoryService.getGlobalEditHistory(beforeId, afterId, count);
|
|
|
|
res.send(result);
|
2019-11-14 07:56:03 -05:00
|
|
|
} catch(error) {
|
2020-01-31 13:02:24 -05:00
|
|
|
if(error instanceof ArgumentError && error.argumentName === 'count') {
|
|
|
|
const apiErr = new ApiParamError(error.message, 'count');
|
|
|
|
throw apiErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
2019-11-14 07:56:03 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export {
|
|
|
|
getGlobalEditHistory
|
|
|
|
};
|