connection request from front to back work and set var in db
This commit is contained in:
parent
d241a0be0d
commit
8740f59325
@ -1,28 +1,37 @@
|
||||
import { Controller, Get, Post } from '@nestjs/common';
|
||||
import { AppService } from './app.service.js';
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
// import { AppService } from './app.service.js';
|
||||
import { UsersService } from './app.service.js';
|
||||
import { User } from './model/item.entity.js';
|
||||
|
||||
|
||||
@Controller()
|
||||
export class AppController2 {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
return this.usersService.getHello();
|
||||
}
|
||||
}
|
||||
|
||||
@Controller('api')
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
// constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get('login')
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
return this.usersService.getHello();
|
||||
}
|
||||
@Post('login')
|
||||
getHello2(): string {
|
||||
return "post";
|
||||
async create(@Body() user: User) {
|
||||
return this.usersService.create(user);
|
||||
}
|
||||
|
||||
// @Get('test')
|
||||
// getHello(): string {
|
||||
// return this.appService.getHello();
|
||||
// }
|
||||
}
|
||||
|
||||
// "clean": "rm -rf /usr/src/app/src && rm -rf /usr/src/app/model && rm -rf /usr/src/app/config && rm -rf *.ts",
|
||||
@ -13,15 +13,18 @@
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller.js';
|
||||
import { AppService } from './app.service.js';
|
||||
import { AppService, UsersService } from './app.service.js';
|
||||
import { User } from './model/item.entity.js';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { getTypeOrmConfig } from './config/config.service.js';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRoot(getTypeOrmConfig())
|
||||
TypeOrmModule.forRoot(getTypeOrmConfig()),
|
||||
TypeOrmModule.forFeature([User]),
|
||||
// TypeOrmModule.forFeature([UserRepository]),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
providers: [AppService, UsersService],
|
||||
})
|
||||
export class AppModule { }
|
||||
@ -1,4 +1,9 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { User } from './model/item.entity.js';
|
||||
// import { User } from './entity/user.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
@ -6,3 +11,35 @@ export class AppService {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(
|
||||
@InjectRepository(User) private userRepository: Repository<User>,
|
||||
) {}
|
||||
// constructor(
|
||||
// @InjectRepository(User)
|
||||
// private usersRepository: Repository<User>,
|
||||
// ) {}
|
||||
// constructor(
|
||||
// @InjectRepository(User)
|
||||
// private usersRepository: Repository<User>,
|
||||
// ) {}
|
||||
// constructor(private usersRepository: Repository<User>) {}
|
||||
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
|
||||
async create(user: User): Promise<User> {
|
||||
return await this.userRepository.save(user);
|
||||
}
|
||||
|
||||
async findAll(): Promise<User[]> {
|
||||
return await this.userRepository.find();
|
||||
}
|
||||
|
||||
// async findOne(id: number): Promise<User> {
|
||||
// return await this.usersRepository.findOne(id);
|
||||
// }
|
||||
}
|
||||
@ -1,86 +1,17 @@
|
||||
// // src/config/config.service.ts
|
||||
// import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
|
||||
// require('dotenv').config();
|
||||
|
||||
// class ConfigService {
|
||||
|
||||
// constructor(private env: { [k: string]: string | undefined }) { }
|
||||
|
||||
// private getValue(key: string, throwOnMissing = true): string {
|
||||
// const value = this.env[key];
|
||||
// if (!value && throwOnMissing) {
|
||||
// throw new Error(`config error - missing env.${key}`);
|
||||
// }
|
||||
|
||||
// return value;
|
||||
// }
|
||||
|
||||
// public ensureValues(keys: string[]) {
|
||||
// keys.forEach(k => this.getValue(k, true));
|
||||
// return this;
|
||||
// }
|
||||
|
||||
// public getPort() {
|
||||
// return this.getValue('PORT', true);
|
||||
// }
|
||||
|
||||
// public isProduction() {
|
||||
// const mode = this.getValue('MODE', false);
|
||||
// return mode != 'DEV';
|
||||
// }
|
||||
|
||||
// public getTypeOrmConfig(): TypeOrmModuleOptions {
|
||||
// return {
|
||||
// type: 'postgres',
|
||||
|
||||
// host: this.getValue('POSTGRES_HOST'),
|
||||
// port: parseInt(this.getValue('POSTGRES_PORT')),
|
||||
// username: this.getValue('POSTGRES_USER'),
|
||||
// password: this.getValue('POSTGRES_PASSWORD'),
|
||||
// database: this.getValue('POSTGRES_DATABASE'),
|
||||
|
||||
// entities: ['**/*.entity{.ts,.js}'],
|
||||
|
||||
// migrationsTableName: 'migration',
|
||||
|
||||
// migrations: ['src/migration/*.ts'],
|
||||
|
||||
// // cli: {
|
||||
// // migrationsDir: 'src/migration',
|
||||
// // },
|
||||
|
||||
// ssl: this.isProduction(),
|
||||
// };
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// const configService = new ConfigService(process.env)
|
||||
// .ensureValues([
|
||||
// 'POSTGRES_HOST',
|
||||
// 'POSTGRES_PORT',
|
||||
// 'POSTGRES_USER',
|
||||
// 'POSTGRES_PASSWORD',
|
||||
// 'POSTGRES_DATABASE'
|
||||
// ]);
|
||||
|
||||
// export { configService };
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* config.service.ts :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/09 14:53:49 by apommier #+# #+# */
|
||||
/* Updated: 2023/04/09 14:55:40 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
// require('dotenv').config();
|
||||
// class ConfigService {
|
||||
export const getTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
||||
// type: 'postgres',
|
||||
// host: process.env.POSTGRES_HOST,
|
||||
// port: parseInt(process.env.POSTGRES_PORT, 10),
|
||||
// username: process.env.POSTGRES_USER,
|
||||
// password: process.env.POSTGRES_PASSWORD,
|
||||
// database: process.env.POSTGRES_DATABASE,
|
||||
// entities: ['**/*.entity{.ts,.js}'],
|
||||
// migrationsTableName: 'migration',
|
||||
// migrations: ['src/migration/*.ts'],
|
||||
// ssl: process.env.MODE !== 'DEV',
|
||||
type: 'postgres',
|
||||
host: 'postgresql',
|
||||
port: 5432,
|
||||
@ -91,6 +22,5 @@ import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
migrationsTableName: 'migration',
|
||||
migrations: ['src/migration/*.ts'],
|
||||
ssl: process.env.MODE !== 'DEV',
|
||||
synchronize: true,
|
||||
});
|
||||
// }
|
||||
// export { ConfigService };
|
||||
@ -34,27 +34,50 @@
|
||||
import { PrimaryGeneratedColumn, Column, UpdateDateColumn, CreateDateColumn } from 'typeorm';
|
||||
|
||||
export abstract class BaseEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
// @PrimaryGeneratedColumn('uuid')
|
||||
// id: string;
|
||||
|
||||
@Column({ type: 'boolean', default: true })
|
||||
isActive: boolean;
|
||||
// @Column({ type: 'boolean', default: true })
|
||||
// isActive: boolean;
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
isArchived: boolean;
|
||||
// @Column({ type: 'boolean', default: false })
|
||||
// isArchived: boolean;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
|
||||
createDateTime: Date;
|
||||
// @CreateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
|
||||
// createDateTime: Date;
|
||||
|
||||
@Column({ type: 'varchar', length: 300 })
|
||||
createdBy: string;
|
||||
// @Column({ type: 'varchar', length: 300 })
|
||||
// createdBy: string;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
|
||||
lastChangedDateTime: Date;
|
||||
// @UpdateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
|
||||
// lastChangedDateTime: Date;
|
||||
|
||||
@Column({ type: 'varchar', length: 300 })
|
||||
lastChangedBy: string;
|
||||
// @Column({ type: 'varchar', length: 300 })
|
||||
// lastChangedBy: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 300, nullable: true })
|
||||
internalComment: string | null;
|
||||
// @Column({ type: 'varchar', length: 300, nullable: true })
|
||||
// internalComment: string | null;
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ nullable: true })
|
||||
nickname: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
Password: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
email: string;
|
||||
|
||||
// @Column({ nullable: true })
|
||||
// password: string;
|
||||
|
||||
@Column({ default: 0 })
|
||||
win: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
loose: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
rank: number;
|
||||
}
|
||||
@ -2,12 +2,12 @@
|
||||
import { Entity, Column } from 'typeorm';
|
||||
import { BaseEntity } from './base.entity.js';
|
||||
|
||||
@Entity({ name: 'item' })
|
||||
export class Item extends BaseEntity {
|
||||
@Entity({ name: 'user' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@Column({ type: 'varchar', length: 300 })
|
||||
@Column({ type: 'varchar', length: 300 , nullable: true})
|
||||
name: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 300 })
|
||||
@Column({ type: 'varchar', length: 300 , nullable: true})
|
||||
description: string;
|
||||
}
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
<form id="loginForm" method="post" name="login" action="/api/login" class ="loginForm">
|
||||
<p class="loginHere">Login Here</p>
|
||||
<input type="text" name="login" placeholder="login">
|
||||
<input type="text" name="nickname" placeholder="login">
|
||||
<input type="text" name="password" placeholder="password">
|
||||
<button class="submit" onclick="login()">LOGIN</button>
|
||||
</form>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user