Skip to content

Commit 6862e98

Browse files
authored
Merge pull request #12 from bonadocs/database-user-repositories
Database user repositories
2 parents be88a99 + 1067032 commit 6862e98

File tree

18 files changed

+74
-37
lines changed

18 files changed

+74
-37
lines changed

src/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getConfigService,
1717
ProjectController,
1818
SubscriptionController,
19+
TenderlyController,
1920
UserController,
2021
} from './modules';
2122

@@ -81,6 +82,7 @@ useExpressServer(app, {
8182
ProjectController,
8283
SubscriptionController,
8384
ContractController,
85+
TenderlyController,
8486
],
8587
middlewares: [AppErrorHandler, AuthMiddleware],
8688
});

src/middleware/errors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Service } from 'typedi';
66

77
import { getGlobalLogger } from '@bonadocs/di';
88

9+
import { ApplicationError } from '../modules/errors';
10+
911
@Service()
1012
@Middleware({ type: 'after' })
1113
export default class AppErrorHandler implements ExpressErrorMiddlewareInterface {
@@ -15,6 +17,14 @@ export default class AppErrorHandler implements ExpressErrorMiddlewareInterface
1517
return;
1618
}
1719

20+
if (error instanceof ApplicationError) {
21+
response.status(error.statusCode).json({
22+
status: error.errorCode,
23+
message: error.userFriendlyMessage,
24+
});
25+
return;
26+
}
27+
1828
if ((<Error>error).name === 'PayloadTooLargeError') {
1929
response.status(StatusCodes.REQUEST_TOO_LONG).json({
2030
status: 'failed',

src/modules/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class AuthService {
5353
userFriendlyMessage: 'Please check your credentials and try again',
5454
});
5555
}
56-
const user = await this.userRepository.findUserByAuth(request.authSource, authUserId, null);
56+
const user = await this.userRepository.findUserByAuth(request.authSource, authUserId);
5757
if (!user) {
5858
throw new ApplicationError({
5959
logger: this.logger,

src/modules/auth/firebase/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import crypto, { createHash } from 'crypto';
22

33
import { Inject, Service } from 'typedi';
44

5-
import { ServiceConfiguration } from '../../configuration/config.interface';
5+
import { GCP } from '../../configuration/config.interface';
66
import { ConfigService } from '../../configuration/config.service';
77

88
let keysCache: { keys: Record<string, string>; expiry: number } | null = null;
@@ -60,8 +60,7 @@ export class FirebaseJWTProvider {
6060
return false;
6161
}
6262

63-
const gcpProjectId =
64-
this.configService.getTransformed<ServiceConfiguration>('gcp').gcp.projectId;
63+
const gcpProjectId = this.configService.getTransformed<GCP>('gcp').projectId;
6564

6665
const nowSeconds = Date.now() / 1000;
6766
if (

src/modules/configuration/config.interface.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,30 @@ export type ServiceConfiguration = {
2323
metaBucket: string;
2424
};
2525
};
26+
27+
export type GCP = {
28+
projectId: string;
29+
collectionsBucket: string;
30+
abisBucket: string;
31+
automergeBucket: string;
32+
metaBucket: string;
33+
};
34+
35+
export type MailGun = {
36+
apiKey: string;
37+
domain: string;
38+
defaultSender: {
39+
name: string;
40+
email: string;
41+
};
42+
};
43+
44+
export type Blockscan = {
45+
etherscan: Record<string, string>;
46+
};
47+
48+
export type Tenderly = {
49+
accessKey: string;
50+
username: string;
51+
project: string;
52+
};

src/modules/connection/dbcontext.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ export function withDbContext<T extends (...args: any[]) => Promise<any>>(
4343
descriptor: TypedPropertyDescriptor<T>,
4444
): TypedPropertyDescriptor<T> {
4545
const originalMethod = descriptor.value!;
46-
return async function wrappedFunction(this: object, ...args: any[]) {
46+
47+
descriptor.value = async function wrappedFunction(this: object, ...args: any[]) {
4748
const lastArg = args[args.length - 1] as DbContext | undefined | null;
4849
const dbContext =
4950
args.length > 0 && lastArg?.isDbContext === true ? (lastArg as DbContext) : undefined;
5051

51-
// if the last argument is a DbContext, we don't need to create a new one
52+
// If the last argument is a DbContext, we don't need to create a new one
5253
if (dbContext) {
5354
return originalMethod.apply(this, args);
5455
}
@@ -104,5 +105,7 @@ export function withDbContext<T extends (...args: any[]) => Promise<any>>(
104105
}
105106
poolClient.release();
106107
}
107-
} as TypedPropertyDescriptor<T>;
108+
} as T;
109+
110+
return descriptor;
108111
}

src/modules/contract/contract.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { diConstants } from '@bonadocs/di';
55
import { BonadocsLogger } from '@bonadocs/logger';
66

77
import { getVerifiedContractABI } from '../blockscan/index';
8-
import { ServiceConfiguration } from '../configuration/config.interface';
8+
import { GCP } from '../configuration/config.interface';
99
import { ConfigService } from '../configuration/config.service';
1010
import { ApplicationError, applicationErrorCodes } from '../errors';
1111
import { EvmContractRepository } from '../repositories/evm-contracts/evm-contracts.repository';
@@ -31,7 +31,7 @@ export class ContractService {
3131
request.chainId,
3232
request.address,
3333
);
34-
const gcpConfig = this.configService.getTransformed<ServiceConfiguration>('gcp').gcp;
34+
const gcpConfig = this.configService.getTransformed<GCP>('gcp');
3535
if (abiHash) {
3636
const abi = await this.storage.downloadFile(gcpConfig.abisBucket, `${abiHash}.json`);
3737

src/modules/errors/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { ApplicationError, applicationErrorCodes } from './ApplicationError';
1+
export * from './ApplicationError';

src/modules/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './project';
55
export * from './user';
66
export * from './contract';
77
export * from './subscription';
8+
export * from './tenderly';

src/modules/mailing/mailgun.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Inject, Service } from 'typedi';
55
import { diConstants } from '@bonadocs/di';
66
import { BonadocsLogger } from '@bonadocs/logger';
77

8-
import { ServiceConfiguration } from '../configuration/config.interface';
8+
import { MailGun } from '../configuration/config.interface';
99
import { ConfigService } from '../configuration/config.service';
1010

1111
import { MailError, MailSender, SenderConfig, SendOptions } from './types';
@@ -45,14 +45,11 @@ export class MailgunSender implements MailSender {
4545

4646
private loadConfig(): MailgunOptions {
4747
return {
48-
domain: this.configService.getTransformed<ServiceConfiguration>('mail').mailgun.domain,
49-
apiKey: this.configService.getTransformed<ServiceConfiguration>('mail').mailgun.apiKey,
48+
domain: this.configService.getTransformed<MailGun>('mail').domain,
49+
apiKey: this.configService.getTransformed<MailGun>('mail').apiKey,
5050
defaultSender: {
51-
email:
52-
this.configService.getTransformed<ServiceConfiguration>('mail').mailgun.defaultSender
53-
.email,
54-
name: this.configService.getTransformed<ServiceConfiguration>('mail').mailgun.defaultSender
55-
.name,
51+
email: this.configService.getTransformed<MailGun>('mail').defaultSender.email,
52+
name: this.configService.getTransformed<MailGun>('mail').defaultSender.name,
5653
},
5754
};
5855
}

0 commit comments

Comments
 (0)