Commit 351874db by Vladislav Lagunov

Исправлен баг в jsonapi-валидаторе

parent 64a3562c
...@@ -213,13 +213,14 @@ export function related(doc: Document, res: Resource, name: string): Validation< ...@@ -213,13 +213,14 @@ export function related(doc: Document, res: Resource, name: string): Validation<
/** validate related resource (one-to-many) */ /** validate related resource (one-to-many) */
export function relatedCollection(doc: Document, res: Resource, name: string): Validation<Resource[]> { export function relatedCollection(doc: Document, res: Resource, name: string): Validation<Resource[]> {
if (doc.included && res.relationships && res.relationships[name]) { if (res.relationships && res.relationships[name]) {
const included = doc.included || [];
const rel: Relationship = res.relationships[name]; const rel: Relationship = res.relationships[name];
if (Array.isArray(rel.data)) { if (Array.isArray(rel.data)) {
const acc: Resource[] = []; const acc: Resource[] = [];
for (let i in rel.data) { for (let i in rel.data) {
const { id, type } = rel.data[i]; const { id, type } = rel.data[i];
const result = doc.included.find(a => a.id === id && a.type === type); const result = included.find(a => a.id === id && a.type === type);
if (result) { if (result) {
acc.push(result); acc.push(result);
} else { } else {
......
...@@ -11,7 +11,7 @@ export function cmpPtr(xs: IArguments, ys: IArguments): boolean { ...@@ -11,7 +11,7 @@ export function cmpPtr(xs: IArguments, ys: IArguments): boolean {
} }
/** cheap partial memoisation, only the last call results are preserved */ /** Cheap partial memoisation, only the last call results are preserved */
export default function memoize<A>(func: () => A, cmp?: ArgsComparator): typeof func; export default function memoize<A>(func: () => A, cmp?: ArgsComparator): typeof func;
export default function memoize<A,B>(func: (a: A) => B, cmp?: ArgsComparator): typeof func; export default function memoize<A,B>(func: (a: A) => B, cmp?: ArgsComparator): typeof func;
export default function memoize<A,B,C>(func: (a: A, b: B) => C, cmp?: ArgsComparator): typeof func; export default function memoize<A,B,C>(func: (a: A, b: B) => C, cmp?: ArgsComparator): typeof func;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment