diff --git a/API_ROUTES.md b/API_ROUTES.md index ee8218c..d3878fd 100644 --- a/API_ROUTES.md +++ b/API_ROUTES.md @@ -585,7 +585,7 @@ Delete a credential and all associated secure values. ### 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. @@ -636,7 +636,7 @@ Fetch a single credential type by its ID or name. ### Get All Credential Types -**GET** `/credential-type/credential-types` +**GET** `/credential-type` Fetch all credential types in the system. @@ -676,7 +676,7 @@ Fetch all credential types in the system. ### Create Credential Type -**POST** `/credential-type/credential-types` +**POST** `/credential-type` Create a new credential type with field definitions. @@ -731,7 +731,7 @@ Create a new credential type with field definitions. ### Update Credential Type -**PATCH** `/credential-type/credential-types/:id` +**PATCH** `/credential-type/:id` 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/credential-types/:id` +**DELETE** `/credential-type/:id` 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** `/credential-type/credential-types/:id/credentials` +**GET** `/credential-type/:id/credentials` Fetch all credentials that use a specific credential type. diff --git a/src/api/credentials/create.ts b/src/api/credentials/create.ts index 3be7fea..1e3011c 100644 --- a/src/api/credentials/create.ts +++ b/src/api/credentials/create.ts @@ -6,7 +6,7 @@ import { ContentfulStatusCode } from "hono/utils/http-status"; import { authMiddleware } from "../middleware/authorization"; import { z } from "zod"; -/* /v1/credential/create */ +/* /v1/credential */ export default createRoute( "post", ["/credentials"], @@ -20,7 +20,6 @@ export default createRoute( companyId: z.string().min(1, "Company ID is required"), fields: z.array( z.object({ - id: z.string(), fieldId: z.string(), value: z.string(), }), diff --git a/src/controllers/CredentialController.ts b/src/controllers/CredentialController.ts index 9046eb8..99d5995 100644 --- a/src/controllers/CredentialController.ts +++ b/src/controllers/CredentialController.ts @@ -46,12 +46,20 @@ export class CredentialController { this.name = credentialData.name; this.typeId = credentialData.typeId; this.companyId = credentialData.companyId; - this.fields = credentialData.fields; this._type = credentialData.type; this._company = credentialData.company; this._secureValues = credentialData.securevalues; + this.fields = (() => { + let fields = credentialData.fields as Record; + + this._secureValues.forEach((sv) => (fields[sv.name] = `secure-${sv.id}`)); + + return fields; + })(); this.createdAt = credentialData.createdAt; this.updatedAt = credentialData.updatedAt; + + console.log(credentialData); } /** diff --git a/src/managers/credentials.ts b/src/managers/credentials.ts index d9bbcb7..f1fa85a 100644 --- a/src/managers/credentials.ts +++ b/src/managers/credentials.ts @@ -75,7 +75,10 @@ export const credentials = { name: string; typeId: string; companyId: string; - fields: CredentialField[]; + fields: { + fieldId: string; + value: string; + }[]; }): Promise { // 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); diff --git a/src/modules/credentials/credentialTypeDefs b/src/modules/credentials/credentialTypeDefs deleted file mode 100644 index e69de29..0000000