Skip to content

Commit 85a2d5c

Browse files
committed
fix: editRecord could break if previous version did not have any data
1 parent 400c022 commit 85a2d5c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/schema/mutation/editRecord.mutation.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { RecordType } from '../types';
1616
import mongoose from 'mongoose';
1717
import { AppAbility } from 'security/defineUserAbility';
18-
import { filter, isEqual, keys, union, has } from 'lodash';
18+
import { filter, isEqual, keys, union, has, get } from 'lodash';
1919
import { logger } from '@services/logger.service';
2020

2121
/**
@@ -31,9 +31,12 @@ export const hasInaccessibleFields = (
3131
newData: any,
3232
ability: AppAbility
3333
) => {
34-
const oldData = record.data;
34+
const oldData = record.data || {};
3535
const k = union(keys(oldData), keys(newData));
36-
const updatedKeys = filter(k, (key) => !isEqual(oldData[key], newData[key]));
36+
const updatedKeys = filter(
37+
k,
38+
(key) => !isEqual(get(oldData, key), get(newData, key))
39+
);
3740

3841
return updatedKeys.some(
3942
(question) =>

0 commit comments

Comments
 (0)