a lot of things
This commit is contained in:
@@ -16,6 +16,7 @@ export default createRoute(
|
||||
|
||||
const schema = z.object({
|
||||
name: z.string().min(1, "Name is required"),
|
||||
notes: z.string().optional(),
|
||||
typeId: z.string().min(1, "Type ID is required"),
|
||||
companyId: z.string().min(1, "Company ID is required"),
|
||||
fields: z.array(
|
||||
|
||||
@@ -5,9 +5,12 @@ import { default as update } from "./update";
|
||||
import { default as updateFields } from "./updateFields";
|
||||
import { default as fetchFields } from "./fetchFields";
|
||||
import { default as readSecureValues } from "./readSecureValues";
|
||||
import { default as readSecureValue } from "./readSecureValue";
|
||||
import { default as deleteCredential } from "./delete";
|
||||
import { default as valueTypes } from "./valueTypes";
|
||||
|
||||
export {
|
||||
valueTypes,
|
||||
fetch,
|
||||
fetchByCompany,
|
||||
create,
|
||||
@@ -15,5 +18,6 @@ export {
|
||||
updateFields,
|
||||
fetchFields,
|
||||
readSecureValues,
|
||||
readSecureValue,
|
||||
deleteCredential as delete,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Hono } from "hono/tiny";
|
||||
import { createRoute } from "../../modules/api-utils/createRoute";
|
||||
import { credentials } from "../../managers/credentials";
|
||||
import { apiResponse } from "../../modules/api-utils/apiResponse";
|
||||
import { ContentfulStatusCode } from "hono/utils/http-status";
|
||||
import { authMiddleware } from "../middleware/authorization";
|
||||
|
||||
/* GET /v1/credential/credentials/:id/secure-values/:fieldId */
|
||||
export default createRoute(
|
||||
"get",
|
||||
["/credentials/:id/secure-values/:fieldId"],
|
||||
|
||||
async (c) => {
|
||||
const credential = await credentials.fetch(c.req.param("id"));
|
||||
const fieldId = c.req.param("fieldId");
|
||||
const value = await credential.readSecureFieldValue(fieldId);
|
||||
|
||||
const response = apiResponse.successful(
|
||||
"Secure Value Fetched Successfully!",
|
||||
{ fieldId, value },
|
||||
);
|
||||
return c.json(response, response.status as ContentfulStatusCode);
|
||||
},
|
||||
authMiddleware({
|
||||
permissions: ["credential.fetch", "credential.secure_values.read"],
|
||||
}),
|
||||
);
|
||||
@@ -17,11 +17,29 @@ export default createRoute(
|
||||
|
||||
const schema = z.object({
|
||||
name: z.string().optional(),
|
||||
notes: z.string().nullable().optional(),
|
||||
fields: z
|
||||
.array(
|
||||
z.object({
|
||||
fieldId: z.string(),
|
||||
value: z.string(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const data = schema.parse(body);
|
||||
|
||||
await credential.update(data);
|
||||
if (data.fields) {
|
||||
await credential.validateAndUpdateFields(data.fields);
|
||||
}
|
||||
|
||||
if (data.name !== undefined || data.notes !== undefined) {
|
||||
await credential.update({
|
||||
...(data.name !== undefined && { name: data.name }),
|
||||
...(data.notes !== undefined && { notes: data.notes }),
|
||||
});
|
||||
}
|
||||
|
||||
const response = apiResponse.successful(
|
||||
"Credential Updated Successfully!",
|
||||
|
||||
@@ -18,7 +18,6 @@ export default createRoute(
|
||||
const schema = z.object({
|
||||
fields: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
fieldId: z.string(),
|
||||
value: z.string(),
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { createRoute } from "../../modules/api-utils/createRoute";
|
||||
import { apiResponse } from "../../modules/api-utils/apiResponse";
|
||||
import { ContentfulStatusCode } from "hono/utils/http-status";
|
||||
import { ValueType } from "../../modules/credentials/credentialTypeDefs";
|
||||
import { authMiddleware } from "../middleware/authorization";
|
||||
|
||||
/* GET /v1/credential/valuetypes */
|
||||
export default createRoute(
|
||||
"get",
|
||||
["/valuetypes"],
|
||||
|
||||
async (c) => {
|
||||
const valueTypes = Object.values(ValueType);
|
||||
|
||||
const response = apiResponse.successful(
|
||||
"Value Types Fetched Successfully!",
|
||||
valueTypes,
|
||||
);
|
||||
return c.json(response, response.status as ContentfulStatusCode);
|
||||
},
|
||||
authMiddleware(),
|
||||
);
|
||||
Reference in New Issue
Block a user