Added metadata creation (#2086)
* Reworked metadata creation * Fix from PR * Removed consolelog
This commit is contained in:
@ -1,77 +1,39 @@
|
||||
import {
|
||||
CreateOneFieldMutation,
|
||||
CreateOneFieldMutationVariables,
|
||||
CreateOneObjectMutation,
|
||||
CreateOneObjectMutationVariables,
|
||||
} from '~/generated-metadata/graphql';
|
||||
|
||||
import { CREATE_ONE_FIELD, CREATE_ONE_OBJECT } from '../graphql/mutations';
|
||||
|
||||
import { useApolloClientMetadata } from './useApolloClientMetadata';
|
||||
import { useCreateOneMetadataField } from './useCreateOneMetadataField';
|
||||
import { useCreateOneMetadataObject } from './useCreateOneMetadataObject';
|
||||
|
||||
export const useSeedCustomObjectsTemp = () => {
|
||||
const client = useApolloClientMetadata();
|
||||
const { createOneMetadataObject } = useCreateOneMetadataObject();
|
||||
const { createOneMetadataField } = useCreateOneMetadataField();
|
||||
|
||||
return async () => {
|
||||
if (!client) return;
|
||||
|
||||
const { data: createSuppliersData } = await client?.mutate<
|
||||
CreateOneObjectMutation,
|
||||
CreateOneObjectMutationVariables
|
||||
>({
|
||||
mutation: CREATE_ONE_OBJECT,
|
||||
variables: {
|
||||
input: {
|
||||
object: {
|
||||
labelPlural: 'Suppliers',
|
||||
labelSingular: 'Supplier',
|
||||
nameSingular: 'supplier',
|
||||
namePlural: 'suppliers',
|
||||
description: 'Suppliers',
|
||||
icon: 'IconBuilding',
|
||||
},
|
||||
},
|
||||
},
|
||||
const createdMetadataObject = await createOneMetadataObject({
|
||||
labelPlural: 'Suppliers',
|
||||
labelSingular: 'Supplier',
|
||||
nameSingular: 'supplier',
|
||||
namePlural: 'suppliers',
|
||||
description: 'Suppliers',
|
||||
icon: 'IconBuilding',
|
||||
});
|
||||
|
||||
const supplierObjectId = createSuppliersData?.createOneObject?.id ?? '';
|
||||
const supplierObjectId =
|
||||
createdMetadataObject.data?.createOneObject?.id ?? '';
|
||||
|
||||
await client?.mutate<
|
||||
CreateOneFieldMutation,
|
||||
CreateOneFieldMutationVariables
|
||||
>({
|
||||
mutation: CREATE_ONE_FIELD,
|
||||
variables: {
|
||||
input: {
|
||||
field: {
|
||||
objectId: supplierObjectId,
|
||||
label: 'Name',
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
description: 'Name',
|
||||
icon: 'IconBuilding',
|
||||
},
|
||||
},
|
||||
},
|
||||
await createOneMetadataField({
|
||||
objectId: supplierObjectId,
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
description: 'Name',
|
||||
label: 'Name',
|
||||
icon: 'IconBuilding',
|
||||
});
|
||||
|
||||
await client?.mutate<
|
||||
CreateOneFieldMutation,
|
||||
CreateOneFieldMutationVariables
|
||||
>({
|
||||
mutation: CREATE_ONE_FIELD,
|
||||
variables: {
|
||||
input: {
|
||||
field: {
|
||||
objectId: supplierObjectId,
|
||||
label: 'City',
|
||||
name: 'city',
|
||||
type: 'text',
|
||||
description: 'City',
|
||||
icon: 'IconMap',
|
||||
},
|
||||
},
|
||||
},
|
||||
await createOneMetadataField({
|
||||
objectId: supplierObjectId,
|
||||
label: 'City',
|
||||
name: 'city',
|
||||
type: 'text',
|
||||
description: 'City',
|
||||
icon: 'IconMap',
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user