Skip to content

Commit 44698b5

Browse files
committed
style: format all
1 parent 6adddda commit 44698b5

File tree

159 files changed

+1477
-1519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+1477
-1519
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

apps/api/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
FROM node:14
22

33
# context path: ./backend
4-
COPY . /app/chainjet/backend
4+
COPY ../.. /app/chainjet/backend
55
WORKDIR /app/chainjet/backend
66

77
RUN yarn
8-
RUN yarn build
8+
RUN yarn build api
99

1010
CMD [ "yarn", "start:prod:api" ]
1111

apps/api/src/account-credentials/account-credentials.module.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import { AccountCredentialService } from './services/account-credentials.service
1515
ConfigModule.forRoot(),
1616
NestjsQueryGraphQLModule.forFeature({
1717
imports: [NestjsQueryTypegooseModule.forFeature([AccountCredential])],
18-
resolvers: []
18+
resolvers: [],
1919
}),
2020
UsersModule, // required for GraphqlGuard
2121
IntegrationsModule,
2222
IntegrationAccountsModule,
23-
forwardRef(() => RunnerModule)
23+
forwardRef(() => RunnerModule),
2424
],
2525
providers: [AccountCredentialResolver, AccountCredentialService, AccountCredentialAuthorizer],
26-
exports: [AccountCredentialService]
26+
exports: [AccountCredentialService],
2727
})
2828
export class AccountCredentialsModule {}

apps/api/src/account-credentials/resolvers/account-credentials.resolver.spec.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ describe('AccountCredentialResolver', () => {
1313

1414
beforeEach(async () => {
1515
const module: TestingModule = await Test.createTestingModule({
16-
imports: [
17-
TypegooseModule.forFeature([AccountCredential]),
18-
MockModule
19-
],
20-
providers: [AccountCredentialResolver, AccountCredentialService, AccountCredentialAuthorizer]
16+
imports: [TypegooseModule.forFeature([AccountCredential]), MockModule],
17+
providers: [AccountCredentialResolver, AccountCredentialService, AccountCredentialAuthorizer],
2118
}).compile()
2219

2320
resolver = module.get<AccountCredentialResolver>(AccountCredentialResolver)

apps/api/src/account-credentials/resolvers/account-credentials.resolver.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { GraphqlGuard } from '../../auth/guards/graphql.guard'
77
import {
88
AccountCredential,
99
CreateAccountCredentialInput,
10-
UpdateAccountCredentialInput
10+
UpdateAccountCredentialInput,
1111
} from '../entities/account-credential'
1212
import { AccountCredentialService } from '../services/account-credentials.service'
1313

@@ -19,11 +19,11 @@ export class AccountCredentialAuthorizer extends OwnedAuthorizer<AccountCredenti
1919
export class AccountCredentialResolver extends BaseResolver(AccountCredential, {
2020
CreateDTOClass: CreateAccountCredentialInput,
2121
UpdateDTOClass: UpdateAccountCredentialInput,
22-
guards: [GraphqlGuard]
22+
guards: [GraphqlGuard],
2323
}) {
24-
constructor (
24+
constructor(
2525
protected accountCredentialService: AccountCredentialService,
26-
@InjectAuthorizer(AccountCredential) readonly authorizer: Authorizer<AccountCredential>
26+
@InjectAuthorizer(AccountCredential) readonly authorizer: Authorizer<AccountCredential>,
2727
) {
2828
super(accountCredentialService)
2929
}

apps/api/src/account-credentials/services/account-credentials.service.spec.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ describe('AccountCredentialService', () => {
1212

1313
beforeEach(async () => {
1414
const module: TestingModule = await Test.createTestingModule({
15-
imports: [
16-
TypegooseModule.forFeature([AccountCredential]),
17-
MockModule
18-
],
19-
providers: [AccountCredentialService]
15+
imports: [TypegooseModule.forFeature([AccountCredential]), MockModule],
16+
providers: [AccountCredentialService],
2017
}).compile()
2118

2219
service = module.get<AccountCredentialService>(AccountCredentialService)

apps/api/src/app.controller.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('AppController', () => {
88
beforeEach(async () => {
99
const app: TestingModule = await Test.createTestingModule({
1010
controllers: [AppController],
11-
providers: [AppService]
11+
providers: [AppService],
1212
}).compile()
1313

1414
appController = app.get<AppController>(AppController)

apps/api/src/app.controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { AppService } from './app.service'
33

44
@Controller()
55
export class AppController {
6-
constructor (private readonly appService: AppService) {}
6+
constructor(private readonly appService: AppService) {}
77

88
@Get()
9-
getHello (): string {
9+
getHello(): string {
1010
return this.appService.getHello()
1111
}
1212
}

apps/api/src/app.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'
22

33
@Injectable()
44
export class AppService {
5-
getHello (): string {
5+
getHello(): string {
66
return 'Hello World!'
77
}
88
}

apps/api/src/auth/auth.module.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,29 @@ import { OwnershipService } from './services/ownership.service'
2323
inject: [ConfigService],
2424
useFactory: (configService: ConfigService) => {
2525
return {
26-
secret: configService.get('JWT_SECRET')
26+
secret: configService.get('JWT_SECRET'),
2727
}
28-
}
28+
},
2929
}),
3030

3131
// Sessions are required for passport-oauth1
3232
SessionModule.forRoot({
3333
// An empty string will make the sesion fail if for some reason a secret is not defined
34-
session: { secret: process.env.SESSION_SECRET ?? '' }
34+
session: { secret: process.env.SESSION_SECRET ?? '' },
3535
}),
3636

3737
UsersModule,
3838
forwardRef(() => AccountCredentialsModule),
3939
ProjectsModule,
4040
IntegrationAccountsModule,
41-
EmailsModule
41+
EmailsModule,
4242
],
4343
providers: [AuthService, AuthResolver, JwtStrategy, OwnershipService, OAuthStrategyFactory],
4444
controllers: [ExternalOAuthController],
45-
exports: [AuthService, OAuthStrategyFactory]
45+
exports: [AuthService, OAuthStrategyFactory],
4646
})
4747
export class AuthModule {
48-
configure (consumer: MiddlewareConsumer): void {
49-
consumer
50-
.apply(OAuthStrategyFactory.initializePassport())
51-
.forRoutes(ExternalOAuthController)
48+
configure(consumer: MiddlewareConsumer): void {
49+
consumer.apply(OAuthStrategyFactory.initializePassport()).forRoutes(ExternalOAuthController)
5250
}
5351
}

apps/api/src/auth/config/admins.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export const ADMIN_USERS = [
2-
'mariano.pardo'
3-
]
1+
export const ADMIN_USERS = ['mariano.pardo']

apps/api/src/auth/decorators/user-id.decorator.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { createParamDecorator, ExecutionContext } from '@nestjs/common'
22
import { GqlExecutionContext } from '@nestjs/graphql'
33

44
// TODO see createGqlParamDecorator
5-
export const UserId = createParamDecorator(
6-
(data: unknown, context: ExecutionContext) => {
7-
const ctx = GqlExecutionContext.create(context)
8-
return ctx.getContext().req.user?.id
9-
}
10-
)
5+
export const UserId = createParamDecorator((data: unknown, context: ExecutionContext) => {
6+
const ctx = GqlExecutionContext.create(context)
7+
return ctx.getContext().req.user?.id
8+
})

apps/api/src/auth/external-oauth/controllers/external-oauth.controller.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('ExternalOAuth Controller', () => {
1111
const module: TestingModule = await Test.createTestingModule({
1212
imports: [MockModule],
1313
controllers: [ExternalOAuthController],
14-
providers: [OAuthStrategyFactory]
14+
providers: [OAuthStrategyFactory],
1515
}).compile()
1616

1717
controller = module.get<ExternalOAuthController>(ExternalOAuthController)

apps/api/src/auth/external-oauth/guards/cookie.guard.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { GqlUserContext } from '../../typings/gql-context'
55

66
@Injectable()
77
export class CookieGuard implements CanActivate {
8-
constructor (private readonly authService: AuthService) {}
8+
constructor(private readonly authService: AuthService) {}
99

10-
canActivate (context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
10+
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
1111
const user = this.getUserFromContext(context)
1212
context.switchToHttp().getRequest().user = user
1313
return !!user?.id
1414
}
1515

16-
getAccessTokenContext (context: ExecutionContext): string | null {
16+
getAccessTokenContext(context: ExecutionContext): string | null {
1717
try {
1818
const cookie = context.switchToHttp().getRequest()?.headers?.cookie
1919
const tokenStr = decodeURIComponent(cookie.split('fw-token=')?.[1]?.split(';')?.[0])
@@ -24,7 +24,7 @@ export class CookieGuard implements CanActivate {
2424
}
2525
}
2626

27-
getUserFromContext (context: ExecutionContext): GqlUserContext | null {
27+
getUserFromContext(context: ExecutionContext): GqlUserContext | null {
2828
try {
2929
const accessToken = this.getAccessTokenContext(context)
3030
if (!accessToken) {
@@ -42,7 +42,7 @@ export class CookieGuard implements CanActivate {
4242
* Loads the user from cookies into the request, but allows the request to continue
4343
*/
4444
export class NotAuthRequiredCookieGuard extends CookieGuard {
45-
async canActivate (context: ExecutionContext): Promise<true> {
45+
async canActivate(context: ExecutionContext): Promise<true> {
4646
await super.canActivate(context)
4747
return true
4848
}

apps/api/src/auth/external-oauth/login-strategies/FacebookLoginStrategy.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@ import { LoginProviderStrategy, LoginStrategyCallback } from './LoginProviderStr
44

55
export class FacebookLoginStrategy extends LoginProviderStrategy {
66
strategyOptions = {
7-
scope: ['email']
7+
scope: ['email'],
88
}
99

10-
constructor (readonly strategyName: string, readonly callbackURL: string) {
10+
constructor(readonly strategyName: string, readonly callbackURL: string) {
1111
super(strategyName, callbackURL)
1212
}
1313

14-
registerStrategy (callback: LoginStrategyCallback): void {
15-
passport.use(this.strategyName, new Strategy({
16-
clientID: process.env.FACEBOOK_CLIENT_ID ?? '',
17-
clientSecret: process.env.FACEBOOK_CLIENT_SECRET ?? '',
18-
callbackURL: this.callbackURL,
19-
profileFields: ['id', 'emails', 'displayName']
20-
}, callback))
14+
registerStrategy(callback: LoginStrategyCallback): void {
15+
passport.use(
16+
this.strategyName,
17+
new Strategy(
18+
{
19+
clientID: process.env.FACEBOOK_CLIENT_ID ?? '',
20+
clientSecret: process.env.FACEBOOK_CLIENT_SECRET ?? '',
21+
callbackURL: this.callbackURL,
22+
profileFields: ['id', 'emails', 'displayName'],
23+
},
24+
callback,
25+
),
26+
)
2127
}
2228
}

apps/api/src/auth/external-oauth/login-strategies/GithubLoginStrategy.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@ import { LoginProviderStrategy, LoginStrategyCallback } from './LoginProviderStr
44

55
export class GithubLoginStrategy extends LoginProviderStrategy {
66
strategyOptions = {
7-
scope: ['user:email']
7+
scope: ['user:email'],
88
}
99

10-
constructor (readonly strategyName: string, readonly callbackURL: string) {
10+
constructor(readonly strategyName: string, readonly callbackURL: string) {
1111
super(strategyName, callbackURL)
1212
}
1313

14-
registerStrategy (callback: LoginStrategyCallback): void {
15-
passport.use(this.strategyName, new Strategy({
16-
clientID: process.env.GITHUB_CLIENT_ID ?? '',
17-
clientSecret: process.env.GITHUB_CLIENT_SECRET ?? '',
18-
callbackURL: this.callbackURL,
19-
scope: ['user:email']
20-
}, callback))
14+
registerStrategy(callback: LoginStrategyCallback): void {
15+
passport.use(
16+
this.strategyName,
17+
new Strategy(
18+
{
19+
clientID: process.env.GITHUB_CLIENT_ID ?? '',
20+
clientSecret: process.env.GITHUB_CLIENT_SECRET ?? '',
21+
callbackURL: this.callbackURL,
22+
scope: ['user:email'],
23+
},
24+
callback,
25+
),
26+
)
2127
}
2228
}

apps/api/src/auth/external-oauth/login-strategies/GoogleLoginStrategy.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ import { LoginProviderStrategy, LoginStrategyCallback } from './LoginProviderStr
44

55
export class GoogleLoginStrategy extends LoginProviderStrategy {
66
strategyOptions = {
7-
scope: ['profile', 'email']
7+
scope: ['profile', 'email'],
88
}
99

10-
constructor (readonly strategyName: string, readonly callbackURL: string) {
10+
constructor(readonly strategyName: string, readonly callbackURL: string) {
1111
super(strategyName, callbackURL)
1212
}
1313

14-
registerStrategy (callback: LoginStrategyCallback): void {
15-
passport.use(this.strategyName, new Strategy({
16-
clientID: process.env.GOOGLE_CLIENT_ID ?? '',
17-
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? '',
18-
callbackURL: this.callbackURL
19-
}, callback))
14+
registerStrategy(callback: LoginStrategyCallback): void {
15+
passport.use(
16+
this.strategyName,
17+
new Strategy(
18+
{
19+
clientID: process.env.GOOGLE_CLIENT_ID ?? '',
20+
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? '',
21+
callbackURL: this.callbackURL,
22+
},
23+
callback,
24+
),
25+
)
2026
}
2127
}

apps/api/src/auth/external-oauth/login-strategies/LoginProviderStrategy.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@ import passport, { Profile } from 'passport'
22

33
export type ProviderCallback = (err?: any, user?: any, info?: any) => void
44

5-
export type LoginProvider =
6-
'google' |
7-
'facebook' |
8-
'github'
5+
export type LoginProvider = 'google' | 'facebook' | 'github'
96

107
export type LoginStrategyCallback = (
118
accessToken: string,
129
refreshToken: string,
1310
profile: Profile,
14-
done: ProviderCallback
11+
done: ProviderCallback,
1512
) => any
1613

1714
export abstract class LoginProviderStrategy {
18-
constructor (readonly strategyName: string, readonly callbackURL: string) {}
15+
constructor(readonly strategyName: string, readonly callbackURL: string) {}
1916

2017
abstract strategyOptions: passport.AuthenticateOptions
2118

22-
abstract registerStrategy (callback: LoginStrategyCallback): void
19+
abstract registerStrategy(callback: LoginStrategyCallback): void
2320
}

apps/api/src/auth/guards/graphql.guard.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ describe('GraphqlGuard', () => {
77

88
beforeEach(async () => {
99
const module: TestingModule = await Test.createTestingModule({
10-
imports: [
11-
MockModule
12-
],
13-
providers: []
10+
imports: [MockModule],
11+
providers: [],
1412
}).compile()
1513

1614
guard = module.get<GraphqlGuard>(GraphqlGuard)

apps/api/src/auth/guards/graphql.guard.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { GqlContext } from '../typings/gql-context'
77

88
@Injectable()
99
export class GraphqlGuard extends AuthGuard('jwt') implements CanActivate {
10-
constructor (private readonly userService: UserService) {
10+
constructor(private readonly userService: UserService) {
1111
super()
1212
}
1313

14-
async canActivate (context: ExecutionContext): Promise<boolean> {
14+
async canActivate(context: ExecutionContext): Promise<boolean> {
1515
const ctx = GqlExecutionContext.create(context)
1616
const req = ctx.getContext().req
1717

@@ -21,8 +21,8 @@ export class GraphqlGuard extends AuthGuard('jwt') implements CanActivate {
2121
const [username, apiKey] = token.split(':')
2222
const user = await this.userService.findOne({ username })
2323
if (user && apiKey && (user.apiKey === apiKey || user.apiKey === `${username}:${apiKey}`)) {
24-
(req.user as AuthPayload) = {
25-
id: user.id
24+
;(req.user as AuthPayload) = {
25+
id: user.id,
2626
}
2727
return true
2828
}
@@ -36,7 +36,7 @@ export class GraphqlGuard extends AuthGuard('jwt') implements CanActivate {
3636
return await canActivate.toPromise()
3737
}
3838

39-
getRequest (context: ExecutionContext): GqlContext['req'] {
39+
getRequest(context: ExecutionContext): GqlContext['req'] {
4040
const ctx = GqlExecutionContext.create(context)
4141
return ctx.getContext().req
4242
}

0 commit comments

Comments
 (0)