MAKING CREDENTIALS WORKS
This commit is contained in:
@@ -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;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user