Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
evereq committed Apr 19, 2024
1 parent 854a32c commit 13d87e1
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 281 deletions.
432 changes: 216 additions & 216 deletions api/src/controllers/project-label.controller.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/src/controllers/project.controller.ts
Expand Up @@ -23,7 +23,7 @@ export default class ProjectController {
private auth: AuthorizationService,
@InjectRepository(Project) private projectRepo: Repository<Project>,
@InjectRepository(ProjectUser) private projectUserRepo: Repository<ProjectUser>,
) { }
) {}

@Get()
@ApiOperation({ summary: 'List projects' })
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/term.controller.ts
Expand Up @@ -21,7 +21,7 @@ export default class TermController {
@InjectRepository(Term) private termRepo: Repository<Term>,
@InjectRepository(Translation) private translationRepo: Repository<Translation>,
@InjectRepository(ProjectLocale) private projectLocaleRepo: Repository<ProjectLocale>,
) { }
) {}

@Get()
@ApiOperation({ summary: `List a project's terms` })
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/translation.controller.ts
Expand Up @@ -32,7 +32,7 @@ export default class TranslationController {
@InjectRepository(Term) private termRepo: Repository<Term>,
@InjectRepository(Locale) private localeRepo: Repository<Locale>,
@InjectRepository(Project) private projectRepo: Repository<Project>,
) { }
) {}

@Get()
@ApiOperation({ summary: 'List all translation locales for a project' })
Expand Down
74 changes: 37 additions & 37 deletions api/src/services/jwt.strategy.ts
Expand Up @@ -10,42 +10,42 @@ import { User } from '../entity/user.entity';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
constructor(
@InjectRepository(User) private readonly userRepository: Repository<User>,
@InjectRepository(ProjectClient) private readonly projectClientRepository: Repository<ProjectClient>,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: config.secret,
});
}
constructor(
@InjectRepository(User) private readonly userRepository: Repository<User>,
@InjectRepository(ProjectClient) private readonly projectClientRepository: Repository<ProjectClient>,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: config.secret,
});
}

/**
*
* @param payload
* @returns
*/
async validate(payload: JwtPayload) {
let user: User | ProjectClient;
switch (payload.type) {
case 'user':
user = await this.userRepository.findOne({
where: { id: payload.sub },
select: ['id', 'name', 'email', 'numProjectsCreated'],
});
break;
case 'client':
user = await this.projectClientRepository.findOne({
where: { id: payload.sub },
select: ['id']
});
break;
default:
break;
}
if (!user) {
throw new UnauthorizedException();
}
return user;
}
/**
*
* @param payload
* @returns
*/
async validate(payload: JwtPayload) {
let user: User | ProjectClient;
switch (payload.type) {
case 'user':
user = await this.userRepository.findOne({
where: { id: payload.sub },
select: ['id', 'name', 'email', 'numProjectsCreated'],
});
break;
case 'client':
user = await this.projectClientRepository.findOne({
where: { id: payload.sub },
select: ['id'],
});
break;
default:
break;
}
if (!user) {
throw new UnauthorizedException();
}
return user;
}
}
2 changes: 1 addition & 1 deletion api/src/services/user.service.ts
Expand Up @@ -15,7 +15,7 @@ export class UserService {
constructor(
@InjectRepository(User) private userRepo: Repository<User>,
@InjectRepository(ProjectUser) private projectUsersRepo: Repository<ProjectUser>,
) { }
) {}

async userExists(email: string): Promise<boolean> {
const normalizedEmail = normalizeEmail(email);
Expand Down
48 changes: 24 additions & 24 deletions api/src/utils/snake-naming-strategy.ts
Expand Up @@ -2,35 +2,35 @@ import { DefaultNamingStrategy, NamingStrategyInterface } from 'typeorm';
import { snakeCase } from 'typeorm/util/StringUtils';

export class SnakeNamingStrategy extends DefaultNamingStrategy implements NamingStrategyInterface {
tableName(className: string, customName: string): string {
return customName ? customName : snakeCase(className);
}
tableName(className: string, customName: string): string {
return customName ? customName : snakeCase(className);
}

columnName(propertyName: string, customName: string, embeddedPrefixes: string[]): string {
return snakeCase(embeddedPrefixes.concat('').join('_')) + (customName ? customName : snakeCase(propertyName));
}
columnName(propertyName: string, customName: string, embeddedPrefixes: string[]): string {
return snakeCase(embeddedPrefixes.concat('').join('_')) + (customName ? customName : snakeCase(propertyName));
}

relationName(propertyName: string): string {
return snakeCase(propertyName);
}
relationName(propertyName: string): string {
return snakeCase(propertyName);
}

joinColumnName(relationName: string, referencedColumnName: string): string {
return snakeCase(`${relationName}_${referencedColumnName}`);
}
joinColumnName(relationName: string, referencedColumnName: string): string {
return snakeCase(`${relationName}_${referencedColumnName}`);
}

joinTableName(firstTableName: string, secondTableName: string, firstPropertyName: string, secondPropertyName: string): string {
return snakeCase(`${firstTableName}_${firstPropertyName.replace(/\./gi, '_')}_${secondTableName}`);
}
joinTableName(firstTableName: string, secondTableName: string, firstPropertyName: string, secondPropertyName: string): string {
return snakeCase(`${firstTableName}_${firstPropertyName.replace(/\./gi, '_')}_${secondTableName}`);
}

joinTableColumnName(tableName: string, propertyName: string, columnName?: string): string {
return snakeCase(`${tableName}_${columnName ? columnName : propertyName}`);
}
joinTableColumnName(tableName: string, propertyName: string, columnName?: string): string {
return snakeCase(`${tableName}_${columnName ? columnName : propertyName}`);
}

classTableInheritanceParentColumnName(parentTableName: any, parentTableIdPropertyName: any): string {
return snakeCase(`${parentTableName}_${parentTableIdPropertyName}`);
}
classTableInheritanceParentColumnName(parentTableName: any, parentTableIdPropertyName: any): string {
return snakeCase(`${parentTableName}_${parentTableIdPropertyName}`);
}

eagerJoinRelationAlias(alias: string, propertyPath: string): string {
return alias + '__' + propertyPath.replace('.', '_');
}
eagerJoinRelationAlias(alias: string, propertyPath: string): string {
return alias + '__' + propertyPath.replace('.', '_');
}
}

0 comments on commit 13d87e1

Please sign in to comment.