MAKING CREDENTIALS WORKS
This commit is contained in:
+6
-6
@@ -585,7 +585,7 @@ Delete a credential and all associated secure values.
|
|||||||
|
|
||||||
### Get Credential Type by ID or Name
|
### Get Credential Type by ID or Name
|
||||||
|
|
||||||
**GET** `/credential-type/credential-types/:identifier`
|
**GET** `/credential-type/:identifier`
|
||||||
|
|
||||||
Fetch a single credential type by its ID or name.
|
Fetch a single credential type by its ID or name.
|
||||||
|
|
||||||
@@ -636,7 +636,7 @@ Fetch a single credential type by its ID or name.
|
|||||||
|
|
||||||
### Get All Credential Types
|
### Get All Credential Types
|
||||||
|
|
||||||
**GET** `/credential-type/credential-types`
|
**GET** `/credential-type`
|
||||||
|
|
||||||
Fetch all credential types in the system.
|
Fetch all credential types in the system.
|
||||||
|
|
||||||
@@ -676,7 +676,7 @@ Fetch all credential types in the system.
|
|||||||
|
|
||||||
### Create Credential Type
|
### Create Credential Type
|
||||||
|
|
||||||
**POST** `/credential-type/credential-types`
|
**POST** `/credential-type`
|
||||||
|
|
||||||
Create a new credential type with field definitions.
|
Create a new credential type with field definitions.
|
||||||
|
|
||||||
@@ -731,7 +731,7 @@ Create a new credential type with field definitions.
|
|||||||
|
|
||||||
### Update Credential Type
|
### Update Credential Type
|
||||||
|
|
||||||
**PATCH** `/credential-type/credential-types/:id`
|
**PATCH** `/credential-type/:id`
|
||||||
|
|
||||||
Update a credential type's properties or field definitions.
|
Update a credential type's properties or field definitions.
|
||||||
|
|
||||||
@@ -794,7 +794,7 @@ Update a credential type's properties or field definitions.
|
|||||||
|
|
||||||
### Delete Credential Type
|
### Delete Credential Type
|
||||||
|
|
||||||
**DELETE** `/credential-type/credential-types/:id`
|
**DELETE** `/credential-type/:id`
|
||||||
|
|
||||||
Delete a credential type. This will cascade delete all credentials of this type.
|
Delete a credential type. This will cascade delete all credentials of this type.
|
||||||
|
|
||||||
@@ -821,7 +821,7 @@ Delete a credential type. This will cascade delete all credentials of this type.
|
|||||||
|
|
||||||
### Get Credentials by Type
|
### Get Credentials by Type
|
||||||
|
|
||||||
**GET** `/credential-type/credential-types/:id/credentials`
|
**GET** `/credential-type/:id/credentials`
|
||||||
|
|
||||||
Fetch all credentials that use a specific credential type.
|
Fetch all credentials that use a specific credential type.
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { ContentfulStatusCode } from "hono/utils/http-status";
|
|||||||
import { authMiddleware } from "../middleware/authorization";
|
import { authMiddleware } from "../middleware/authorization";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
/* /v1/credential/create */
|
/* /v1/credential */
|
||||||
export default createRoute(
|
export default createRoute(
|
||||||
"post",
|
"post",
|
||||||
["/credentials"],
|
["/credentials"],
|
||||||
@@ -20,7 +20,6 @@ export default createRoute(
|
|||||||
companyId: z.string().min(1, "Company ID is required"),
|
companyId: z.string().min(1, "Company ID is required"),
|
||||||
fields: z.array(
|
fields: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
id: z.string(),
|
|
||||||
fieldId: z.string(),
|
fieldId: z.string(),
|
||||||
value: z.string(),
|
value: z.string(),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -46,12 +46,20 @@ export class CredentialController {
|
|||||||
this.name = credentialData.name;
|
this.name = credentialData.name;
|
||||||
this.typeId = credentialData.typeId;
|
this.typeId = credentialData.typeId;
|
||||||
this.companyId = credentialData.companyId;
|
this.companyId = credentialData.companyId;
|
||||||
this.fields = credentialData.fields;
|
|
||||||
this._type = credentialData.type;
|
this._type = credentialData.type;
|
||||||
this._company = credentialData.company;
|
this._company = credentialData.company;
|
||||||
this._secureValues = credentialData.securevalues;
|
this._secureValues = credentialData.securevalues;
|
||||||
|
this.fields = (() => {
|
||||||
|
let fields = credentialData.fields as Record<string, any>;
|
||||||
|
|
||||||
|
this._secureValues.forEach((sv) => (fields[sv.name] = `secure-${sv.id}`));
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
})();
|
||||||
this.createdAt = credentialData.createdAt;
|
this.createdAt = credentialData.createdAt;
|
||||||
this.updatedAt = credentialData.updatedAt;
|
this.updatedAt = credentialData.updatedAt;
|
||||||
|
|
||||||
|
console.log(credentialData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -75,7 +75,10 @@ export const credentials = {
|
|||||||
name: string;
|
name: string;
|
||||||
typeId: string;
|
typeId: string;
|
||||||
companyId: string;
|
companyId: string;
|
||||||
fields: CredentialField[];
|
fields: {
|
||||||
|
fieldId: string;
|
||||||
|
value: string;
|
||||||
|
}[];
|
||||||
}): Promise<CredentialController> {
|
}): Promise<CredentialController> {
|
||||||
// Fetch the credential type to get acceptable fields
|
// Fetch the credential type to get acceptable fields
|
||||||
const credentialType = await prisma.credentialType.findFirst({
|
const credentialType = await prisma.credentialType.findFirst({
|
||||||
@@ -92,14 +95,17 @@ export const credentials = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate the fields against acceptable fields
|
// Validate the fields against acceptable fields
|
||||||
const acceptableFields = JSON.parse(credentialType.fields! as string).map(
|
const acceptableFields = (
|
||||||
(f: { id: string; name: string; secure: boolean }) => ({
|
credentialType.fields! as any as CredentialTypeField[]
|
||||||
id: f.id,
|
).map((f: { id: string; name: string; secure: boolean }) => ({
|
||||||
name: f.name,
|
id: f.id,
|
||||||
secure: f.secure,
|
name: f.name,
|
||||||
}),
|
secure: f.secure,
|
||||||
) as CredentialTypeField[];
|
})) as CredentialTypeField[];
|
||||||
const validatedFields = await fieldValidator(data.fields, acceptableFields);
|
const validatedFields = await fieldValidator(
|
||||||
|
data.fields as any as CredentialField[],
|
||||||
|
acceptableFields,
|
||||||
|
);
|
||||||
|
|
||||||
// Separate secure and non-secure fields
|
// Separate secure and non-secure fields
|
||||||
const secureFields = validatedFields.filter((f) => f.secure);
|
const secureFields = validatedFields.filter((f) => f.secure);
|
||||||
|
|||||||
Reference in New Issue
Block a user