Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddie023 committed Oct 21, 2024
1 parent d3e85db commit d7e93f2
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
- uses: oven-sh/setup-bun@v2
- run: bun install

- name: Build
run: make build

- name: Lint
run: bun run lint

- name: Build
run: make build

- name: Test
run: bun test
3 changes: 1 addition & 2 deletions src/user/entities/group.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, PrimaryColumn } from 'typeorm';
import { User } from './user.entity';
import { Column, Entity, PrimaryColumn } from 'typeorm';

@Entity('groups')
export class Group {
Expand Down
11 changes: 5 additions & 6 deletions src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Column, Entity, JoinTable, ManyToMany, PrimaryColumn, JoinColumn } from 'typeorm';
import { Column, Entity, JoinTable, ManyToMany, PrimaryColumn } from 'typeorm';

import { Group } from './group.entity';

@Entity('users')
Expand All @@ -24,9 +25,7 @@ export class User {
@Column({ default: false, name: 'is_verified' })
isVerified: boolean;

@ManyToMany(type => Group)
@JoinTable({name: "user_group"})
groups: Group[]
@ManyToMany(() => Group)
@JoinTable({ name: 'user_group' })
groups: Group[];
}


4 changes: 2 additions & 2 deletions src/user/entities/usergroup.entity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Column, Entity, PrimaryColumn } from 'typeorm';
import { Column, Entity } from 'typeorm';

@Entity('user_group')
export class UserGroup {
@Column({name: "user_id"})
@Column({ name: 'user_id' })
user_id: string;

@Column()
Expand Down
2 changes: 1 addition & 1 deletion src/user/user.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { beforeEach, describe, expect, mock, test } from 'bun:test';

import { UserController } from './user.controller';
import { User } from './user.entity';
import { User } from './entities/user.entity';
import { UserService } from './user.service';

const mockUserRepository = {
Expand Down
2 changes: 1 addition & 1 deletion src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export class UserController {

@Get(':id/groups')
getAllUserGroups(@Param('id') id: string) {
return this.userService.getUserGroups(id)
return this.userService.getUserGroups(id);
}
}
2 changes: 1 addition & 1 deletion src/user/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { LoggerModule } from 'nestjs-pino';

import { UserController } from './user.controller';
import { User } from './entities/user.entity';
import { UserController } from './user.controller';
import { UserService } from './user.service';

@Module({
Expand Down
4 changes: 2 additions & 2 deletions src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ describe('UserService', () => {
lastName: 'jobs',
isVerified: true,
createdAt: new Date(),
updatedAt: new Date()
updatedAt: new Date(),
groups: []
};
userRepository.findOneBy.mockResolvedValue(want);

Expand All @@ -52,4 +53,3 @@ describe('UserService', () => {
});
});
});

6 changes: 3 additions & 3 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ export class UserService {
return this.usersRepository.findOneBy({ id });
}

// TODO: use TyeORM functionalities for many to many relation.
// TODO: use TyeORM functionalities for many to many relation.
async getUserGroups(userId: string) {
const userGroups = await this.usersRepository.query(
`
`
SELECT u.id, u.email, groups.id as group_id, groups.name, groups.description
FROM users u
INNER JOIN user_group ug ON ug.user_id = u.id
INNER JOIN groups ON ug.group_id = groups.id
WHERE u.id = '${userId}';
`
)
);
return userGroups;
}
}

0 comments on commit d7e93f2

Please sign in to comment.