Skip to content

Commit

Permalink
fix: package and few other minor updates
Browse files Browse the repository at this point in the history
Signed-off-by: vikastc <[email protected]>
  • Loading branch information
Vikastc committed Sep 27, 2024
1 parent 1de63dc commit 61bfefc
Show file tree
Hide file tree
Showing 8 changed files with 927 additions and 800 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AUTHOR_URI=//sparknet/agent
CHAIN_SPACE_ID=space:cord:c35h1XGuUXDHwtJTre7dwsb7KqZM5DWYA4kpPRuSx6BZJnXTg
CHAIN_SPACE_AUTH=auth:cord:a3fHEajeParsSaCNLffgi9UVL3dieXNrufHujvdorccQ94qqv
MNEMONIC=loyal federal rare goddess chief display vessel athlete vault fork grab eager strategy lonely current foster eager toe holiday unveil heavy city belt agent

TYPEORM_PORT=5432

STUDIO_TYPEORM_HOST=postgres30
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.mac
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ RUN mkdir -p /tmp/templates

EXPOSE 5001

CMD ["node", "dist/index.js"]
CMD ["npm", "run", "prod"]

#CMD ["tail", "-f", "/dev/null"]
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
"dotenv": "^16.0.3",
"express": "^4.18.2",
"moment": "^2.30.1",
"nodemon": "^2.0.21",
"nodemon": "^3.1.7",
"pg": "^8.10.0",
"reflect-metadata": "^0.1.13",
"swagger-ui-express": "^4.6.2",
"reflect-metadata": "^0.2.2",
"swagger-ui-express": "^5.0.1",
"ts-node": "^10.9.1",
"typeorm": "^0.2.31",
"uuid": "^9.0.0",
"typeorm": "^0.3.20",
"uuid": "^10.0.0",
"yamljs": "^0.3.0"
},
"devDependencies": {
"@types/cors": "^2.8.14",
"@types/express": "^4.17.17",
"@types/node": "^20.11.0",
"@types/express": "^5.0.0",
"@types/node": "^22.7.3",
"@types/swagger-ui-express": "^4.1.3",
"@types/uuid": "^9.0.1",
"@types/uuid": "^10.0.0",
"@types/yamljs": "^0.2.34",
"typescript": "^4.9.5"
"typescript": "^5.6.2"
}
}
22 changes: 11 additions & 11 deletions src/controller/credential_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
delegateKeysProperty,
} from '../init';

import { getConnection } from 'typeorm';
import { Cred } from '../entity/Cred';
import { Schema } from '../entity/Schema';
import { dataSource } from '../dbconfig';
const { CHAIN_SPACE_ID, CHAIN_SPACE_AUTH } = process.env;

export async function issueVC(req: express.Request, res: express.Response) {
Expand All @@ -26,9 +26,9 @@ export async function issueVC(req: express.Request, res: express.Response) {
}

try {
const schema = await getConnection()
const schema = await dataSource
.getRepository(Schema)
.findOne({ identifier: data.schemaId });
.findOne({ where: { identifier: data.schemaId } });

const parsedSchema = JSON.parse(schema?.cordSchema as string);

Expand Down Expand Up @@ -88,7 +88,7 @@ export async function issueVC(req: express.Request, res: express.Response) {
cred.vc = vc;

if (statement) {
await getConnection().manager.save(cred);
await dataSource.manager.save(cred);
return res
.status(200)
.json({ result: 'success', identifier: cred.identifier });
Expand Down Expand Up @@ -131,9 +131,9 @@ export async function issueVC(req: express.Request, res: express.Response) {

export async function getCredById(req: express.Request, res: express.Response) {
try {
const cred = await getConnection()
const cred = await dataSource
.getRepository(Cred)
.findOne({ identifier: req.params.id });
.findOne({ where: { identifier: req.params.id } });

if (!cred) {
return res.status(400).json({ error: 'Cred not found' });
Expand All @@ -156,9 +156,9 @@ export async function updateCred(req: express.Request, res: express.Response) {
}

try {
const cred = await getConnection()
const cred = await dataSource
.getRepository(Cred)
.findOne({ identifier: req.params.id });
.findOne({ where: { identifier: req.params.id } });

if (!cred) {
return res.status(400).json({ error: 'Cred not found' });
Expand Down Expand Up @@ -215,7 +215,7 @@ export async function updateCred(req: express.Request, res: express.Response) {
cred.credHash = updatedCredContent.credentialHash;
cred.vc = updatedVc;

await getConnection().manager.save(cred);
await dataSource.manager.save(cred);

console.log('\n✅ Statement updated!');

Expand All @@ -233,9 +233,9 @@ export async function updateCred(req: express.Request, res: express.Response) {

export async function revokeCred(req: express.Request, res: express.Response) {
try {
const cred = await getConnection()
const cred = await dataSource
.getRepository(Cred)
.findOne({ identifier: req.params.id });
.findOne({ where: { identifier: req.params.id } });

if (!cred) {
return res.status(400).json({ error: 'Invalid identifier' });
Expand Down
8 changes: 4 additions & 4 deletions src/controller/schema_controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Cord from '@cord.network/sdk';
import express from 'express';
import { getConnection } from 'typeorm';
import 'reflect-metadata';

import { Schema } from '../entity/Schema';
Expand All @@ -10,6 +9,7 @@ import {
issuerDid,
issuerKeysProperty,
} from '../init';
import { dataSource } from '../dbconfig';

const { CHAIN_SPACE_ID, CHAIN_SPACE_AUTH } = process.env;

Expand Down Expand Up @@ -67,7 +67,7 @@ export async function createSchema(
schemaData.cordSchema = JSON.stringify(schemaDetails);
schemaData.requiredFields = data.required;

await getConnection().manager.save(schemaData);
await dataSource.manager.save(schemaData);
return res.status(200).json({
result: 'SUCCESS',
schemaId: schemaData.identifier,
Expand All @@ -85,9 +85,9 @@ export async function getSchemaById(
res: express.Response
) {
try {
const schema = await getConnection()
const schema = await dataSource
.getRepository(Schema)
.findOne({ identifier: req.params.id });
.findOne({ where: { identifier: req.params.id } });

if (!schema) {
return res.status(400).json({ error: 'Schema not found' });
Expand Down
6 changes: 4 additions & 2 deletions src/dbconfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectionOptions } from 'typeorm';
import { DataSource, DataSourceOptions } from 'typeorm';

const {
TYPEORM_HOST,
Expand All @@ -16,7 +16,7 @@ const {
TYPEORM_SUBSCRIBERS_DIR,
} = process.env;

export const dbConfig: ConnectionOptions = {
const dbConfig = {
type: 'postgres',
host: TYPEORM_HOST,
port: parseInt(TYPEORM_PORT as string),
Expand All @@ -34,3 +34,5 @@ export const dbConfig: ConnectionOptions = {
subscribersDir: TYPEORM_SUBSCRIBERS_DIR as string,
},
};

export const dataSource = new DataSource(dbConfig as DataSourceOptions);
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import app from './server';
import express from 'express';
import { createConnection } from 'typeorm';
import { dbConfig } from './dbconfig';
import { dataSource } from './dbconfig';
import { addDelegateAsRegistryDelegate } from './init';
import {
createSchema,
Expand Down Expand Up @@ -60,7 +59,7 @@ app.get('/*', async (req, res) => {

async function main() {
try {
await createConnection(dbConfig);
await dataSource.initialize();
await addDelegateAsRegistryDelegate();
} catch (error) {
console.log('error: ', error);
Expand Down
Loading

0 comments on commit 61bfefc

Please sign in to comment.