Skip to content

Commit

Permalink
[Feat] User model + service + controller
Browse files Browse the repository at this point in the history
Created user model with is able to store different platform logins.
References #16.
  • Loading branch information
angel-penchev committed Oct 5, 2021
1 parent 57c61fe commit ef19b9a
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 46 deletions.
22 changes: 0 additions & 22 deletions server/src/app.controller.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions server/src/app.controller.ts

This file was deleted.

6 changes: 2 additions & 4 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ConfigModule, ConfigService } from '@nestjs/config';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { configuration } from './configuration';
Expand All @@ -22,7 +20,7 @@ const envFilePath = !environment ? '.env' : `.env.${environment}`;
configService.get('database'),
}),
],
controllers: [AppController],
providers: [AppService],
controllers: [],
providers: [],
})
export class AppModule {}
8 changes: 0 additions & 8 deletions server/src/app.service.ts

This file was deleted.

18 changes: 18 additions & 0 deletions server/src/users/controllers/users.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersController } from './users.controller';

describe('UsersController', () => {
let controller: UsersController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
}).compile();

controller = module.get<UsersController>(UsersController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
4 changes: 4 additions & 0 deletions server/src/users/controllers/users.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';

@Controller('/users')
export class UsersController {}
47 changes: 47 additions & 0 deletions server/src/users/models/user.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

@Entity({ name: 'users' })
export class User implements IUser {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ unique: true })
username: string;

@Column({ nullable: true })
password: string;

@Column({ nullable: true, unique: true })
email: string;

@Column({ name: 'phone_number', nullable: true })
phoneNumber: string;

@Column({ name: 'google_id', nullable: true, unique: true })
googleId: string;

@Column({ name: 'discord_id', nullable: true, unique: true })
discordId: string;

@Column({ name: 'github_id', nullable: true, unique: true })
githubId: string;

@Column({ nullable: true })
name: string;

@Column({ nullable: true })
avatar: string;
}

export interface IUser {
id?: string;
username: string;
password?: string;
email?: string;
phoneNumber?: string;
googleId?: string;
discordId?: string;
githubId?: string;
name?: string;
avatar?: string;
}
18 changes: 18 additions & 0 deletions server/src/users/services/users.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersService } from './users.service';

describe('UsersService', () => {
let service: UsersService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UsersService],
}).compile();

service = module.get<UsersService>(UsersService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
4 changes: 4 additions & 0 deletions server/src/users/services/users.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class UsersService {}
10 changes: 10 additions & 0 deletions server/src/users/users.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './models/user.model';
import { UsersService } from './services/users.service';

@Module({
providers: [UsersService],
imports: [TypeOrmModule.forFeature([User])],
})
export class UsersModule {}

0 comments on commit ef19b9a

Please sign in to comment.