MAKING CREDENTIALS WORKS

This commit is contained in:
2026-02-15 16:38:04 -06:00
parent cdae4d47a4
commit 6d951e426d
5 changed files with 31 additions and 18 deletions
+6 -6
View File
@@ -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.
+1 -2
View File
@@ -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(),
}),
+9 -1
View File
@@ -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<string, any>;
this._secureValues.forEach((sv) => (fields[sv.name] = `secure-${sv.id}`));
return fields;
})();
this.createdAt = credentialData.createdAt;
this.updatedAt = credentialData.updatedAt;
console.log(credentialData);
}
/**
+12 -6
View File
@@ -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 }) => ({
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, acceptableFields);
})) 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);