add users
This commit is contained in:
11
.prettierrc
11
.prettierrc
@@ -1,4 +1,11 @@
|
||||
{
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
"trailingComma": "all",
|
||||
"printWidth": 100,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "auto"
|
||||
}
|
||||
|
||||
1252
package-lock.json
generated
1252
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@@ -20,9 +20,18 @@
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hapi/joi": "^17.1.1",
|
||||
"@neondatabase/serverless": "^1.0.0",
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@nestjs/typeorm": "^11.0.0",
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/hapi__joi": "^17.1.15",
|
||||
"bcrypt": "^5.1.1",
|
||||
"joi": "^17.13.3",
|
||||
"pg": "^8.15.6",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
@@ -38,12 +47,12 @@
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-prettier": "^5.2.2",
|
||||
"eslint": "^9.26.0",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"eslint-plugin-prettier": "^5.4.0",
|
||||
"globals": "^16.0.0",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier": "^3.5.3",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-jest": "^29.2.5",
|
||||
|
||||
@@ -1,9 +1,29 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
imports: [
|
||||
TypeOrmModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
type: 'postgres',
|
||||
host: configService.get<string>('POSTGRES_HOST'),
|
||||
port: parseInt(configService.get<string>('POSTGRES_PORT', '5432'), 10),
|
||||
username: configService.get<string>('POSTGRES_USER'),
|
||||
password: configService.get<string>('POSTGRES_PASSWORD'),
|
||||
database: configService.get<string>('POSTGRES_DB'),
|
||||
ssl: {
|
||||
rejectUnauthorized: false, // Needed for Neon and similar managed DBs
|
||||
},
|
||||
synchronize: true, // Disable in production
|
||||
}),
|
||||
}),
|
||||
ConfigModule.forRoot(),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
||||
7
src/users/dto/createUser.dto.ts
Normal file
7
src/users/dto/createUser.dto.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export class CreateUserDto {
|
||||
email: string;
|
||||
name: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default CreateUserDto;
|
||||
18
src/users/user.entity.ts
Normal file
18
src/users/user.entity.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
class User {
|
||||
@PrimaryGeneratedColumn()
|
||||
public id?: number;
|
||||
|
||||
@Column({ unique: true })
|
||||
public email: string;
|
||||
|
||||
@Column()
|
||||
public name: string;
|
||||
|
||||
@Column()
|
||||
public password: string;
|
||||
}
|
||||
|
||||
export default User;
|
||||
11
src/users/user.module.ts
Normal file
11
src/users/user.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import User from './user.entity';
|
||||
import { UsersService } from './user.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User])],
|
||||
providers: [UsersService],
|
||||
exports: [UsersService],
|
||||
})
|
||||
export class UsersModule {}
|
||||
30
src/users/user.service.ts
Normal file
30
src/users/user.service.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import User from './user.entity';
|
||||
import CreateUserDto from './dto/createUser.dto';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private usersRepository: Repository<User>,
|
||||
) {}
|
||||
|
||||
async getByEmail(email: string) {
|
||||
const user = await this.usersRepository.findOne({ where: { email } });
|
||||
if (user) {
|
||||
return user;
|
||||
}
|
||||
throw new HttpException(
|
||||
'User with this email does not exist',
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
async create(userData: CreateUserDto) {
|
||||
const newUser = this.usersRepository.create(userData);
|
||||
await this.usersRepository.save(newUser);
|
||||
return newUser;
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,11 @@
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false,
|
||||
"lib": ["dom"] // dom.value is required for the browser
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user