feat: disable atomic operation on nestjs graphql models (#751)
* feat: no atomic * feat: update front not atomic operations * feat: optional fields for person model & use proper gql type * Fix bug display name * Fix bug update user * Fixed bug avatar URL * Fixed display name on people cell * Fix lint * Fixed storybook display name * Fix storybook requests --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -7,6 +7,8 @@ import {
|
||||
UserOrderByWithRelationInput,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import { isDefined } from '../../utils/isDefined';
|
||||
|
||||
function filterData<DataT>(
|
||||
data: Array<DataT>,
|
||||
where: Record<string, any>,
|
||||
@ -135,15 +137,28 @@ export function fetchOneFromData<DataT extends { id: string }>(
|
||||
data: Array<DataT>,
|
||||
id: string,
|
||||
): DataT | undefined {
|
||||
if (!isDefined(id)) {
|
||||
throw new Error(
|
||||
`id is not defined in updateOneFromData, check that you provided where.id if needed.`,
|
||||
);
|
||||
}
|
||||
|
||||
return data.filter((item) => item.id === id)[0];
|
||||
}
|
||||
|
||||
export function updateOneFromData<DataT extends { id: string }>(
|
||||
data: Array<DataT>,
|
||||
id: string,
|
||||
id: string | undefined,
|
||||
payload: GraphQLVariables,
|
||||
): DataT | undefined {
|
||||
if (!isDefined(id)) {
|
||||
throw new Error(
|
||||
`id is not defined in updateOneFromData, check that you provided where.id if needed.`,
|
||||
);
|
||||
}
|
||||
|
||||
const object = data.filter((item) => item.id === id)[0];
|
||||
|
||||
const newObject = Object.assign(object, payload);
|
||||
|
||||
return newObject;
|
||||
|
||||
Reference in New Issue
Block a user