MAKING CREDENTIALS WORKS
This commit is contained in:
@@ -75,7 +75,10 @@ export const credentials = {
|
||||
name: string;
|
||||
typeId: string;
|
||||
companyId: string;
|
||||
fields: CredentialField[];
|
||||
fields: {
|
||||
fieldId: string;
|
||||
value: string;
|
||||
}[];
|
||||
}): Promise<CredentialController> {
|
||||
// Fetch the credential type to get acceptable fields
|
||||
const credentialType = await prisma.credentialType.findFirst({
|
||||
@@ -92,14 +95,17 @@ export const credentials = {
|
||||
}
|
||||
|
||||
// Validate the fields against acceptable fields
|
||||
const acceptableFields = JSON.parse(credentialType.fields! as string).map(
|
||||
(f: { id: string; name: string; secure: boolean }) => ({
|
||||
id: f.id,
|
||||
name: f.name,
|
||||
secure: f.secure,
|
||||
}),
|
||||
) as CredentialTypeField[];
|
||||
const validatedFields = await fieldValidator(data.fields, acceptableFields);
|
||||
const acceptableFields = (
|
||||
credentialType.fields! as any as CredentialTypeField[]
|
||||
).map((f: { id: string; name: string; secure: boolean }) => ({
|
||||
id: f.id,
|
||||
name: f.name,
|
||||
secure: f.secure,
|
||||
})) as CredentialTypeField[];
|
||||
const validatedFields = await fieldValidator(
|
||||
data.fields as any as CredentialField[],
|
||||
acceptableFields,
|
||||
);
|
||||
|
||||
// Separate secure and non-secure fields
|
||||
const secureFields = validatedFields.filter((f) => f.secure);
|
||||
|
||||
Reference in New Issue
Block a user