Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/relationship-responders.js
// @flow | // @flow | ||||
import t, { type TInterface } from 'tcomb'; | import t, { type TInterface } from 'tcomb'; | ||||
import { | import { | ||||
type RelationshipRequest, | type RelationshipRequest, | ||||
type RelationshipErrors, | type RelationshipErrors, | ||||
relationshipActionsList, | relationshipActionsList, | ||||
} from 'lib/types/relationship-types.js'; | } from 'lib/types/relationship-types.js'; | ||||
import { tShape } from 'lib/utils/validation-utils.js'; | import { tShape } from 'lib/utils/validation-utils.js'; | ||||
import type { Viewer } from '../session/viewer.js'; | import type { Viewer } from '../session/viewer.js'; | ||||
import { updateRelationships } from '../updaters/relationship-updaters.js'; | import { updateRelationships } from '../updaters/relationship-updaters.js'; | ||||
import { validateInput } from '../utils/validation-utils.js'; | import { validateInput, validateOutput } from '../utils/validation-utils.js'; | ||||
const updateRelationshipInputValidator = tShape({ | const updateRelationshipInputValidator = tShape({ | ||||
action: t.enums.of(relationshipActionsList, 'relationship action'), | action: t.enums.of(relationshipActionsList, 'relationship action'), | ||||
userIDs: t.list(t.String), | userIDs: t.list(t.String), | ||||
}); | }); | ||||
export const relationshipErrorsValidator: TInterface<RelationshipErrors> = | export const relationshipErrorsValidator: TInterface<RelationshipErrors> = | ||||
tShape<RelationshipErrors>({ | tShape<RelationshipErrors>({ | ||||
invalid_user: t.maybe(t.list(t.String)), | invalid_user: t.maybe(t.list(t.String)), | ||||
already_friends: t.maybe(t.list(t.String)), | already_friends: t.maybe(t.list(t.String)), | ||||
user_blocked: t.maybe(t.list(t.String)), | user_blocked: t.maybe(t.list(t.String)), | ||||
}); | }); | ||||
async function updateRelationshipsResponder( | async function updateRelationshipsResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
input: any, | input: any, | ||||
): Promise<RelationshipErrors> { | ): Promise<RelationshipErrors> { | ||||
const request: RelationshipRequest = input; | const request: RelationshipRequest = input; | ||||
await validateInput(viewer, updateRelationshipInputValidator, request); | await validateInput(viewer, updateRelationshipInputValidator, request); | ||||
return await updateRelationships(viewer, request); | const response = await updateRelationships(viewer, request); | ||||
return validateOutput(viewer, relationshipErrorsValidator, response); | |||||
} | } | ||||
export { updateRelationshipsResponder }; | export { updateRelationshipsResponder }; |