Skip to content

Commit

Permalink
feat: Allow adding metadata of uploading data
Browse files Browse the repository at this point in the history
  • Loading branch information
wsy19961129 committed Oct 22, 2024
1 parent 62e7db8 commit cd13c11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/itmat-apis/src/trpc/dataProcedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const CreateFieldInputSchema = z.object({
unit: z.optional(z.string()),
comments: z.optional(z.string()),
verifier: z.optional(z.array(z.array(ZValueVerifier))),
properties: z.optional(z.array(ZFieldProperty))
properties: z.optional(z.array(ZFieldProperty)),
metadata: z.optional(z.record(z.string(), z.unknown()))
});

const EditFieldInputSchema = CreateFieldInputSchema;
Expand Down Expand Up @@ -108,7 +109,8 @@ export class DataRouter {
unit: opts.input.unit,
comments: opts.input.comments,
verifier: opts.input.verifier,
properties: opts.input.properties
properties: opts.input.properties,
metadata: opts.input.metadata
});
}),
/**
Expand Down Expand Up @@ -288,7 +290,7 @@ export class DataRouter {
*/
getFiles: this.baseProcedure.input(z.object({
studyId: z.string(),
versionId: z.optional(z.string()),
versionId: z.optional(z.union([z.string(), z.null(), z.array(z.union([z.string(), z.null()]))])),
fieldIds: z.optional(z.array(z.string())),
readable: z.optional(z.boolean()),
useCache: z.optional(z.boolean()),
Expand Down
3 changes: 2 additions & 1 deletion packages/itmat-cores/src/coreFunc/dataCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface CreateFieldInput {
comments?: string;
verifier?: ValueVerifierInput[][];
properties?: IFieldProperty[];
metadata?: Record<string, unknown>;
}

type EditFieldInput = CreateFieldInput;
Expand Down Expand Up @@ -255,7 +256,7 @@ export class DataCore {
deletedTime: null,
deletedUser: null
},
metadata: {}
metadata: fieldInput.metadata ?? {}
};

await this.db.collections.field_dictionary_collection.insertOne(fieldEntry);
Expand Down
3 changes: 2 additions & 1 deletion packages/itmat-cores/src/utils/GraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export function convertV2CreateFieldInputToV3(studyId: string, fields: V2CreateF
required: false
}],
unit: field.unit,
comments: field.comments
comments: field.comments,
metadata: field.metadata
};
});
}
Expand Down

0 comments on commit cd13c11

Please sign in to comment.