MAKING CREDENTIALS WORKS

This commit is contained in:
2026-02-15 16:38:55 -06:00
parent 140e6c416a
commit 561aef8ee3
4 changed files with 580 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
import api from "./axios";
export interface CredentialField {
id: string;
fieldId: string;
value: string;
}
export interface Credential {
id: string;
name: string;
typeId: string;
companyId: string;
fields: CredentialField[];
type?: {
id: string;
name: string;
fields: unknown[];
permissionScope: string;
};
company?: {
id: string;
name: string;
};
createdAt: string;
updatedAt: string;
}
export const credential = {
async fetchByCompany(accessToken: string, companyId: string) {
const response = await api.get(
`/v1/credential/credentials/company/${companyId}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);
return response.data;
},
async fetch(accessToken: string, id: string) {
const response = await api.get(`/v1/credential/credentials/${id}`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
return response.data;
},
async create(
accessToken: string,
data: Omit<Credential, "id" | "createdAt" | "updatedAt">,
) {
console.log(data);
const response = await api.post("/v1/credential/credentials", data, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
return response.data;
},
async update(accessToken: string, id: string, data: { name: string }) {
const response = await api.patch(`/v1/credential/credentials/${id}`, data, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
return response.data;
},
async updateFields(
accessToken: string,
id: string,
fields: CredentialField[],
) {
const response = await api.put(
`/v1/credential/credentials/${id}/fields`,
{ fields },
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);
return response.data;
},
async delete(accessToken: string, id: string) {
const response = await api.delete(`/v1/credential/credentials/${id}`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
return response.data;
},
};