Skip to content

Table(User):create the user table used for authentication setup #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions admin/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,8 @@
}
}
}
},
"cli": {
"analytics": "20cbecd5-2859-428e-8894-90d2b9fff99a"
}
}
6,931 changes: 6,931 additions & 0 deletions admin/yarn.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@nestjs/common": "^11.0.1",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.0.1",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^11.0.1",
"@nestjs/terminus": "^11.0.0",
"@prisma/client": "^6.6.0",
Expand Down
30 changes: 27 additions & 3 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,31 @@ datasource db {
}

model User {
id Int @id @default(autoincrement())
email String @unique
name String?
id Int @id @default(autoincrement())
role Role @default(Patient) // Enum: Patient, Practitioner, Admin
firstName String
lastName String
password String
temporaryAccount Boolean
phoneNumber String @unique()
country String
sex Sex // Enum: male, female, other
status Status @default(not_approved) // Enum: approved, not_approved
}

enum Role {
Patient
Practitioner
Admin
}

enum Sex {
male
female
other
}

enum Status {
approved
not_approved
}
4 changes: 4 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { AppController } from './app.controller';
import { AppService } from './app.service';
import { DatabaseModule } from './database/database.module';
import { HealthModule } from './health/health.module';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';

@Module({
imports: [
Expand All @@ -13,6 +15,8 @@ import { HealthModule } from './health/health.module';
}),
DatabaseModule,
HealthModule,
AuthModule,
UserModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
18 changes: 18 additions & 0 deletions backend/src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';

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

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

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

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

@Controller('auth')
export class AuthController {}
9 changes: 9 additions & 0 deletions backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';

@Module({
controllers: [AuthController],
providers: [AuthService]
})
export class AuthModule {}
18 changes: 18 additions & 0 deletions backend/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';

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

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

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

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

@Injectable()
export class AuthService {}
22 changes: 22 additions & 0 deletions backend/src/common/helpers/response-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export function successResponse<T>(
data: T,
message = 'Success',
statusCode = 200,
) {
return {
statusCode,
message,
data,
};
}

export function errorResponse(
message = 'Something went wrong',
statusCode = 500,
) {
return {
statusCode,
message,
};
}

4 changes: 2 additions & 2 deletions backend/src/database/database.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { Module,Global } from '@nestjs/common';
import { DatabaseService } from './database.service';

@Global()
@Module({
providers: [DatabaseService],
exports: [DatabaseService],
Expand Down
20 changes: 20 additions & 0 deletions backend/src/user/user.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UserController } from './user.controller';
import { UserService } from './user.service';

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

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

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

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
34 changes: 34 additions & 0 deletions backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { UserService } from './user.service';
import { Prisma } from '@prisma/client';
import { DatabaseModule } from 'src/database/database.module';

@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}

@Post()
create(@Body() data:Prisma.UserCreateInput) {
return this.userService.create(data);
}

@Get()
findAll() {
return this.userService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.userService.findOne(+id);
}

// @Patch(':id')
// update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
// return this.userService.update(+id, updateUserDto);
// }

@Delete(':id')
remove(@Param('id') id: string) {
return this.userService.remove(+id);
}
}
11 changes: 11 additions & 0 deletions backend/src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { DatabaseModule } from 'src/database/database.module';

@Module({
controllers: [UserController],
providers: [UserService],
imports:[DatabaseModule]
})
export class UserModule {}
18 changes: 18 additions & 0 deletions backend/src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UserService } from './user.service';

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

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

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

it('should be defined', () => {
expect(service).toBeDefined();
});
});
32 changes: 32 additions & 0 deletions backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Injectable } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { DatabaseService } from 'src/database/database.service';
import { successResponse } from 'src/common/helpers/response-helper';
@Injectable()
export class UserService {
constructor(private readonly databaseService:DatabaseService){}



async create(data:Prisma.UserCreateInput) {
const user= await this.databaseService.user.create({data});
return successResponse(user, "user sucessfully created", 201)
}

async findAll() {
const users= await this.databaseService.user.findMany();
return successResponse(users, "users sucessfully fetched")
}

findOne(id: number) {
return `This action returns a #${id} user`;
}

// update(id: number) {
// return `This action updates a #${id} user`;
// }

remove(id: number) {
return `This action removes a #${id} user`;
}
}
5 changes: 5 additions & 0 deletions backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,11 @@
path-to-regexp "8.2.0"
tslib "2.8.1"

"@nestjs/mapped-types@*":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@nestjs/mapped-types/-/mapped-types-2.1.0.tgz#b9b536b7c3571567aa1d0223db8baa1a51505a19"
integrity sha512-W+n+rM69XsFdwORF11UqJahn4J3xi4g/ZEOlJNL6KoW5ygWSmBB2p0S2BZ4FQeS/NDH72e6xIcu35SfJnE8bXw==

"@nestjs/platform-express@^11.0.1":
version "11.0.13"
resolved "https://registry.yarnpkg.com/@nestjs/platform-express/-/platform-express-11.0.13.tgz#f5748a3ba91ab50e4aa808668a34952b239c6e0b"
Expand Down