Skip to content

Commit

Permalink
Merge pull request #290 from credebl/api-standardization-for-schema-m…
Browse files Browse the repository at this point in the history
…odule

Api standardization for schema module
  • Loading branch information
16-karan authored Sep 21, 2023
2 parents 326076a + cff3d0f commit 2f1783e
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 225 deletions.
25 changes: 13 additions & 12 deletions src/api/Schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GetAllSchemaListParameter, createCredDeffFieldName, createSchema } from "../components/Resources/Schema/interfaces";
import { axiosDelete, axiosGet, axiosPost } from "../services/apiRequests";
import { axiosGet, axiosPost } from "../services/apiRequests";

import { apiRoutes } from "../config/apiRoutes";
import { getFromLocalStorage } from "./Auth";
Expand All @@ -8,7 +8,7 @@ import { storageKeys } from "../config/CommonConstant";
export const getAllSchemas = async ({itemPerPage, page, allSearch }: GetAllSchemaListParameter) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: `${apiRoutes.schema.getAllSchemaFromPlatform}?pageSize=${itemPerPage}&searchByText=${allSearch}&pageNumber=${page}`,
url: `${apiRoutes.Platform.getAllSchemaFromPlatform}?pageSize=${itemPerPage}&searchByText=${allSearch}&pageNumber=${page}`,
config: {
headers: {
'Content-type': 'application/json',
Expand All @@ -30,7 +30,7 @@ export const getAllSchemas = async ({itemPerPage, page, allSearch }: GetAllSchem
export const getAllSchemasByOrgId = async ({ search, itemPerPage, page }: GetAllSchemaListParameter, orgId: string) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: `${apiRoutes.schema.getAll}?orgId=${orgId}&pageNumber=${page}&pageSize=${itemPerPage}&searchByText=${search}`,
url: `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getAll}?pageNumber=${page}&pageSize=${itemPerPage}&searchByText=${search}`,
config: {
headers: {
'Content-type': 'application/json',
Expand All @@ -49,10 +49,10 @@ export const getAllSchemasByOrgId = async ({ search, itemPerPage, page }: GetAll
}
}

export const addSchema = async (payload: createSchema) => {
export const addSchema = async (payload: createSchema, orgId: number) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: apiRoutes.schema.create,
url: `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.create}`,
payload,
config: {
headers: {
Expand All @@ -72,10 +72,10 @@ export const addSchema = async (payload: createSchema) => {
}
}

export const getSchemaById = async (id: string, orgId: number) => {
export const getSchemaById = async (schemaId: string, orgId: number) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: `${apiRoutes.schema.getSchemaById}?schemaId=${id}&orgId=${orgId}`,
url: `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getSchemaById}/${schemaId}`,
config: {
headers: {
'Content-type': 'application/json',
Expand All @@ -94,10 +94,10 @@ export const getSchemaById = async (id: string, orgId: number) => {
}
}

export const createCredentialDefinition = async (payload: createCredDeffFieldName) => {
export const createCredentialDefinition = async (payload: createCredDeffFieldName, orgId:number) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: apiRoutes.schema.createCredentialDefinition,
url: `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.createCredentialDefinition}`,
payload,
config: {
headers: {
Expand All @@ -118,10 +118,10 @@ export const createCredentialDefinition = async (payload: createCredDeffFieldNam
}
}

export const getCredDeffById = async (id: string, orgId: number) => {
export const getCredDeffById = async (schemaId: string, orgId: number) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: `${apiRoutes.schema.getCredDeffBySchemaId}?schemaId=${id}&orgId=${orgId}`,
url: `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`,
config: {
headers: {
'Content-type': 'application/json',
Expand All @@ -138,4 +138,5 @@ export const getCredDeffById = async (id: string, orgId: number) => {
const err = error as Error
return err?.message
}
}
}

8 changes: 4 additions & 4 deletions src/api/issuance.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { IssueCredential } from '../common/enums';
import { apiRoutes } from '../config/apiRoutes';
import { storageKeys } from '../config/CommonConstant';
import { getHeaderConfigs } from '../config/GetHeaderConfigs';
import { axiosGet, axiosPost } from '../services/apiRequests';
import { getFromLocalStorage } from './Auth';

export const getIssuedCredentials = async (state: IssueCredential) => {
export const getIssuedCredentials = async (schemaId: string) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Issuance.getIssuedCredentials}?orgId=${orgId}`;
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`;

const axiosPayload = {
url,
Expand All @@ -24,7 +23,8 @@ export const getIssuedCredentials = async (state: IssueCredential) => {

export const getCredentialDefinitions = async (schemaId: string) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Issuance.getCredDefBySchemaId}?schemaId=${schemaId}&orgId=${orgId}`;
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`;

const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand Down
2 changes: 1 addition & 1 deletion src/api/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const getProofAttributes=async (id:string)=>{
}

export const getCredentialDefinitionsForVerification = async (schemaId: string) => {
const url = `${apiRoutes.Issuance.getCredDefBySchemaId}?schemaId=${schemaId}`;
const url = `${apiRoutes.schema.getCredDefBySchemaId}?schemaId=${schemaId}`;
const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand Down
7 changes: 5 additions & 2 deletions src/commonComponents/CredentialDefinitionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ const CredDeffCard = (props: { credDeffName: string, userRoles?:string[], creden
type="submit"
color='bg-primary-800'
title='Initiate Credential Issuance'
className='transform transition duration-500 hover:scale-105 hover:bg-gray-50 dark:text-white bg-primary-700 bg-transparent ring-primary-700 ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5'
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700
ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2
lg:py-2.5 mr-2 ml-auto dark:text-white dark:hover:text-black
dark:hover:bg-primary-50'
style={{ height: '1.5rem', width: '100%', minWidth: '2rem' }}
>
<div className='mr-2'>
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="none" viewBox="0 0 23 23">  <path fill="#030300" fill-rule="evenodd" d="M21 21H2V2h9.5V0H2.556A2.563 2.563 0 0 0 0 2.556v17.888A2.563 2.563 0 0 0 2.556 23h17.888A2.563 2.563 0 0 0 23 20.444V11.5h-2V21ZM14.056 0v2H19.5l-13 13 1 1.5L21 3v5.944h2V0h-8.944Z" clip-rule="evenodd" />
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="none" viewBox="0 0 23 23">  <path fill="#1F4EAD" fill-rule="evenodd" d="M21 21H2V2h9.5V0H2.556A2.563 2.563 0 0 0 0 2.556v17.888A2.563 2.563 0 0 0 2.556 23h17.888A2.563 2.563 0 0 0 23 20.444V11.5h-2V21ZM14.056 0v2H19.5l-13 13 1 1.5L21 3v5.944h2V0h-8.944Z" clip-rule="evenodd" />
</svg>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/commonComponents/DeletePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const DeleteModal = (props: { openModal: boolean; closeModal: (flag: boolean) =>
</svg>
<p className="mb-4 text-gray-500 dark:text-gray-300">
Are you sure you want to revoke{' '}
<span className="dark:text-black font-bold">{props.deviceName}</span> device?
<span className="dark:text-white font-bold">{props.deviceName}</span> device?
</p>
<div className="flex justify-center items-center space-x-4">
<button
Expand Down
4 changes: 2 additions & 2 deletions src/components/Authentication/FooterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const FooterBar = () => {
<p className="text-sm text-center text-gray-500">
&copy; 2019 - {new Date().getFullYear()} -
<a className="hover:underline" target="_blank"
>CREDEBL
>Blockster Labs
</a> | All rights reserved.
</p>

Expand All @@ -17,4 +17,4 @@ const FooterBar = () => {
)
}

export default FooterBar;
export default FooterBar;
2 changes: 1 addition & 1 deletion src/components/CopyrightNotice.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p class="my-10 text-sm text-center text-gray-500">
&copy; 2019 - {new Date().getFullYear()}
&copy; 2019 - {new Date().getFullYear()}
<a class="hover:underline" target="_blank"
> Blockster Labs Private Limited</a
> | All rights reserved.
Expand Down
5 changes: 4 additions & 1 deletion src/components/Issuance/Connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ const Connections = () => {
onClick={() => {
window.location.href = `${pathRoutes.back.issuance.credDef}`
}}
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700 ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 m-2 ml-auto dark:text-white'
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700
ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2
lg:py-2.5 mr-2 ml-auto dark:text-white dark:hover:text-black
dark:hover:bg-primary-50'
style={{ height: '2.5rem', width: '5rem', minWidth: '2rem' }}
>
<svg className='mr-1' xmlns="http://www.w3.org/2000/svg" width="22" height="12" fill="none" viewBox="0 0 30 20">
Expand Down
1 change: 0 additions & 1 deletion src/components/Issuance/CredDefSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import SchemaCard from "../../commonComponents/SchemaCard";
import type { TableData } from "../../commonComponents/datatable/interface";
import { dateConversion } from "../../utils/DateConversion";
import { getCredentialDefinitions } from "../../api/issuance";
import { getSchemaById } from "../../api/Schema";
import { pathRoutes } from "../../config/pathRoutes";
import DateTooltip from "../Tooltip";

Expand Down
13 changes: 8 additions & 5 deletions src/components/Issuance/Issuance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Yup from 'yup';
import { Alert, Button, Card } from 'flowbite-react';
import { ErrorMessage, Field, Form, Formik } from 'formik';
import { apiStatusCodes, storageKeys } from '../../config/CommonConstant';
import { getCredDeffById, getSchemaById } from '../../api/Schema';
// import { getCredDeffById, getSchemaById } from '../../api/Schema';
import { getFromLocalStorage, removeFromLocalStorage } from '../../api/Auth';
import { useEffect, useState } from 'react';

Expand Down Expand Up @@ -197,7 +197,10 @@ const IssueCred = () => {
onClick={() => {
window.location.href =`${pathRoutes.back.issuance.connections}`
}}
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700 ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 m-2 ml-2 dark:text-white'
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700
ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2
lg:py-2.5 mr-2 ml-auto dark:text-white dark:hover:text-black
dark:hover:bg-primary-50'
style={{ height: '2.5rem', width: '5rem', minWidth: '2rem' }}
>
<svg className='mr-1' xmlns="http://www.w3.org/2000/svg" width="22" height="12" fill="none" viewBox="0 0 30 20">
Expand Down Expand Up @@ -283,17 +286,17 @@ const IssueCred = () => {
Connection Id
</h5>
<span className='text-xl font-bold leading-none dark:text-white pl-1'>:</span>
<p className="pl-1">{user.connectionId}</p>
<p className="dark:text-white pl-1">{user.connectionId}</p>
</div>
<h3 className="">Attributes</h3>
<h3 className="dark:text-white">Attributes</h3>
<div className="container mx-auto pr-2">
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-2">
{schemaAttributesDetails.map((attr, index) => (
<div>
<div key={index} className="flex">
<label
htmlFor={`attributes.${index}.value`}
className="w-1/3 pr-2 flex justify-end items-center font-light"
className="dark:text-white w-1/3 pr-2 flex justify-end items-center font-light"
>
{attr.displayName.charAt(0).toUpperCase() +
attr.displayName.slice(1).toLowerCase() + ":"}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Issuance/IssuedCrdentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const CredentialList = () => {
</div>
) : (
<div>
<span className="block text-center p-4 m-8">
<span className="dark:text-white block text-center p-4 m-8">
There isn't any data available.
</span>
</div>
Expand Down
20 changes: 11 additions & 9 deletions src/components/Resources/Schema/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SchemaCard from '../../../commonComponents/SchemaCard';
import { addSchema } from '../../../api/Schema';
import { getFromLocalStorage } from '../../../api/Auth';
import { pathRoutes } from '../../../config/pathRoutes';
import React from 'react';

const options = [
{ value: 'string', label: 'String' },
Expand Down Expand Up @@ -46,7 +47,7 @@ import { pathRoutes } from '../../../config/pathRoutes';
orgId: orgId,
};

const createSchema = await addSchema(schemaFieldName);
const createSchema = await addSchema(schemaFieldName, orgId);
const { data } = createSchema as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) {

Expand Down Expand Up @@ -200,8 +201,8 @@ import { pathRoutes } from '../../../config/pathRoutes';

return (
<>
<div className="d-flex justify-content-center align-items-center mb-1">
Attributes <span className="text-red-600">*</span>
<div className="dark:text-white d-flex justify-content-center align-items-center mb-1">
Attributes <span className="dark:text-white text-red-600">*</span>

</div>
<div className="flex flex-col">
Expand Down Expand Up @@ -539,6 +540,7 @@ import { pathRoutes } from '../../../config/pathRoutes';
No, cancel
</button>
<Button
data-modal-hide="popup-modal"
type="submit"
isProcessing={createloader}
disabled={createloader}
Expand All @@ -556,15 +558,15 @@ import { pathRoutes } from '../../../config/pathRoutes';
<Button
type="reset"
color='bg-primary-800'
onClick={() => {
setCredDefAuto('')
}}
// onClick={() => {
// setCredDefAuto('')
// }}
disabled={createloader}
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700 ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 mr-2 ml-auto'
className='dark:text-white bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700 ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 mr-2 ml-auto'

style={{ height: '2.6rem', width: '6rem', minWidth: '2rem' }}
>
<svg xmlns="http://www.w3.org/2000/svg" className='mr-2' width="18" height="18" fill="none" viewBox="0 0 20 20">
<svg xmlns="http://www.w3.org/2000/svg" className= 'mr-2' width="18" height="18" fill="none" viewBox="0 0 20 20">
<path fill="#1F4EAD" d="M19.414 9.414a.586.586 0 0 0-.586.586c0 4.868-3.96 8.828-8.828 8.828-4.868 0-8.828-3.96-8.828-8.828 0-4.868 3.96-8.828 8.828-8.828 1.96 0 3.822.635 5.353 1.807l-1.017.18a.586.586 0 1 0 .204 1.153l2.219-.392a.586.586 0 0 0 .484-.577V1.124a.586.586 0 0 0-1.172 0v.928A9.923 9.923 0 0 0 10 0a9.935 9.935 0 0 0-7.071 2.929A9.935 9.935 0 0 0 0 10a9.935 9.935 0 0 0 2.929 7.071A9.935 9.935 0 0 0 10 20a9.935 9.935 0 0 0 7.071-2.929A9.935 9.935 0 0 0 20 10a.586.586 0 0 0-.586-.586Z" />
</svg>

Expand All @@ -581,4 +583,4 @@ import { pathRoutes } from '../../../config/pathRoutes';
);
};

export default CreateSchema;
export default CreateSchema;
Loading

0 comments on commit 2f1783e

Please sign in to comment.