Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/report-responders.js
// @flow | // @flow | ||||
import type { $Response, $Request } from 'express'; | import type { $Response, $Request } from 'express'; | ||||
import t from 'tcomb'; | import t from 'tcomb'; | ||||
import type { TStructProps } from 'tcomb'; | import type { TInterface, TStructProps } from 'tcomb'; | ||||
import { | import { | ||||
type ReportCreationResponse, | type ReportCreationResponse, | ||||
type ReportCreationRequest, | type ReportCreationRequest, | ||||
type FetchErrorReportInfosResponse, | type FetchErrorReportInfosResponse, | ||||
type FetchErrorReportInfosRequest, | type FetchErrorReportInfosRequest, | ||||
type ThreadInconsistencyReportShape, | type ThreadInconsistencyReportShape, | ||||
type EntryInconsistencyReportShape, | type EntryInconsistencyReportShape, | ||||
reportTypes, | reportTypes, | ||||
reportInfoValidator, | |||||
} from 'lib/types/report-types.js'; | } from 'lib/types/report-types.js'; | ||||
import { userInfoValidator } from 'lib/types/user-types.js'; | |||||
import { ServerError } from 'lib/utils/errors.js'; | import { ServerError } from 'lib/utils/errors.js'; | ||||
import { | import { | ||||
tShape, | tShape, | ||||
tPlatform, | tPlatform, | ||||
tPlatformDetails, | tPlatformDetails, | ||||
} from 'lib/utils/validation-utils.js'; | } from 'lib/utils/validation-utils.js'; | ||||
import { newEntryQueryInputValidator } from './entry-responders.js'; | import { newEntryQueryInputValidator } from './entry-responders.js'; | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | tShape({ | ||||
actions: t.list(t.union([t.Object, t.String])), | actions: t.list(t.union([t.Object, t.String])), | ||||
}), | }), | ||||
threadInconsistencyReportCreationRequest, | threadInconsistencyReportCreationRequest, | ||||
entryInconsistencyReportCreationRquest, | entryInconsistencyReportCreationRquest, | ||||
mediaMissionReportCreationRequest, | mediaMissionReportCreationRequest, | ||||
userInconsistencyReportCreationRequest, | userInconsistencyReportCreationRequest, | ||||
]); | ]); | ||||
export const reportCreationResponseValidator: TInterface<ReportCreationResponse> = | |||||
tShape<ReportCreationResponse>({ id: t.String }); | |||||
async function reportCreationResponder( | async function reportCreationResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
input: any, | input: any, | ||||
): Promise<ReportCreationResponse> { | ): Promise<ReportCreationResponse> { | ||||
await validateInput(viewer, reportCreationRequestInputValidator, input); | await validateInput(viewer, reportCreationRequestInputValidator, input); | ||||
if (input.type === null || input.type === undefined) { | if (input.type === null || input.type === undefined) { | ||||
input.type = reportTypes.ERROR; | input.type = reportTypes.ERROR; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | await Promise.all( | ||||
), | ), | ||||
); | ); | ||||
} | } | ||||
const fetchErrorReportInfosRequestInputValidator = tShape({ | const fetchErrorReportInfosRequestInputValidator = tShape({ | ||||
cursor: t.maybe(t.String), | cursor: t.maybe(t.String), | ||||
}); | }); | ||||
export const fetchErrorReportInfosResponseValidator: TInterface<FetchErrorReportInfosResponse> = | |||||
tShape<FetchErrorReportInfosResponse>({ | |||||
reports: t.list(reportInfoValidator), | |||||
userInfos: t.list(userInfoValidator), | |||||
}); | |||||
async function errorReportFetchInfosResponder( | async function errorReportFetchInfosResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
input: any, | input: any, | ||||
): Promise<FetchErrorReportInfosResponse> { | ): Promise<FetchErrorReportInfosResponse> { | ||||
const request: FetchErrorReportInfosRequest = input; | const request: FetchErrorReportInfosRequest = input; | ||||
await validateInput( | await validateInput( | ||||
viewer, | viewer, | ||||
fetchErrorReportInfosRequestInputValidator, | fetchErrorReportInfosRequestInputValidator, | ||||
Show All 30 Lines |