-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c10d1b5
commit aea3272
Showing
7 changed files
with
123 additions
and
51 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { parse } from 'pg-connection-string' | ||
import { DataSource } from 'typeorm' | ||
import { migrations, Entities } from '@veramo/data-store' | ||
import { CustomerEntity } from '../entities/customer.entity' | ||
|
||
const { ISSUER_DATABASE_URL} = process.env | ||
|
||
export class Connection { | ||
public dbConnection : DataSource | ||
public static instance = new Connection() | ||
|
||
constructor () { | ||
const config = parse(ISSUER_DATABASE_URL) | ||
if(!(config.host && config.port && config.database)) { | ||
throw new Error(`Error: Invalid Database url`) | ||
} | ||
|
||
this.dbConnection = new DataSource({ | ||
type: 'postgres', | ||
host: config.host, | ||
port: Number(config.port), | ||
username: config.user, | ||
password: config.password, | ||
database: config.database, | ||
ssl: config.ssl ? true : false, | ||
migrations, | ||
entities: [...Entities, CustomerEntity], | ||
synchronize: true, | ||
logging: ['error', 'info', 'warn'] | ||
}) | ||
} | ||
|
||
public async connect() { | ||
try { | ||
await this.dbConnection.initialize() | ||
} catch (error) { | ||
throw new Error(`Error initializing db: ${error}`) | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm' | ||
|
||
@Entity('customers') | ||
export class CustomerEntity { | ||
@Column('string') | ||
customerId | ||
|
||
@Column('string', {array: true}) | ||
kids | ||
|
||
@Column('string', {array: true}) | ||
dids: string[] | ||
|
||
@Column('string', {array: true}) | ||
claimIds: string[] | ||
|
||
@Column('string', {array: true}) | ||
presentationIds: string[] | ||
|
||
constructor({ customerId, kids=[], dids=[], claimIds=[], presentationIds=[] }: { customerId: string, kids?: string[], dids?: string[], claimIds?: string[], presentationIds?: string[]}) { | ||
this.customerId = customerId | ||
this.kids = kids | ||
this.dids = dids | ||
this.claimIds = claimIds | ||
this.presentationIds = presentationIds | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Connection } from '../database/connection/connection' | ||
import { CustomerEntity } from '../database/entities/customer.entity' | ||
|
||
|
||
export class CustomerService { | ||
public async create(customer: CustomerEntity) { | ||
return await Connection.instance.dbConnection.manager.save(customer) | ||
} | ||
|
||
public async update(customer: CustomerEntity, customerId: string) { | ||
return await Connection.instance.dbConnection.manager.save({ customerId, customer }) | ||
} | ||
|
||
public async get() { | ||
return await Connection.instance.dbConnection.manager.find(CustomerEntity) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters