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 { Body, Controller, Get, Post } from '@nestjs/common';
|
||||||
import { AppService } from './app.service.js';
|
// import { AppService } from './app.service.js';
|
||||||
|
import { UsersService } from './app.service.js';
|
||||||
|
import { User } from './model/item.entity.js';
|
||||||
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController2 {
|
export class AppController2 {
|
||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly usersService: UsersService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
return this.appService.getHello();
|
return this.usersService.getHello();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Controller('api')
|
@Controller('api')
|
||||||
export class AppController {
|
export class AppController {
|
||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly usersService: UsersService) {}
|
||||||
|
// constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
@Get('login')
|
@Get('login')
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
return this.appService.getHello();
|
return this.usersService.getHello();
|
||||||
}
|
}
|
||||||
@Post('login')
|
@Post('login')
|
||||||
getHello2(): string {
|
async create(@Body() user: User) {
|
||||||
return "post";
|
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",
|
// "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 { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller.js';
|
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 { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { getTypeOrmConfig } from './config/config.service.js';
|
import { getTypeOrmConfig } from './config/config.service.js';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forRoot(getTypeOrmConfig())
|
TypeOrmModule.forRoot(getTypeOrmConfig()),
|
||||||
|
TypeOrmModule.forFeature([User]),
|
||||||
|
// TypeOrmModule.forFeature([UserRepository]),
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService, UsersService],
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
@ -1,4 +1,9 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
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()
|
@Injectable()
|
||||||
export class AppService {
|
export class AppService {
|
||||||
@ -6,3 +11,35 @@ export class AppService {
|
|||||||
return 'Hello World!';
|
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();
|
/* config.service.ts :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
// class ConfigService {
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
// constructor(private env: { [k: string]: string | undefined }) { }
|
/* Created: 2023/04/09 14:53:49 by apommier #+# #+# */
|
||||||
|
/* Updated: 2023/04/09 14:55:40 by apommier ### ########.fr */
|
||||||
// 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 };
|
|
||||||
|
|
||||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||||
// require('dotenv').config();
|
|
||||||
// class ConfigService {
|
|
||||||
export const getTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
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',
|
type: 'postgres',
|
||||||
host: 'postgresql',
|
host: 'postgresql',
|
||||||
port: 5432,
|
port: 5432,
|
||||||
@ -91,6 +22,5 @@ import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|||||||
migrationsTableName: 'migration',
|
migrationsTableName: 'migration',
|
||||||
migrations: ['src/migration/*.ts'],
|
migrations: ['src/migration/*.ts'],
|
||||||
ssl: process.env.MODE !== 'DEV',
|
ssl: process.env.MODE !== 'DEV',
|
||||||
});
|
synchronize: true,
|
||||||
// }
|
});
|
||||||
// export { ConfigService };
|
|
||||||
@ -34,27 +34,50 @@
|
|||||||
import { PrimaryGeneratedColumn, Column, UpdateDateColumn, CreateDateColumn } from 'typeorm';
|
import { PrimaryGeneratedColumn, Column, UpdateDateColumn, CreateDateColumn } from 'typeorm';
|
||||||
|
|
||||||
export abstract class BaseEntity {
|
export abstract class BaseEntity {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
// @PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
// id: string;
|
||||||
|
|
||||||
@Column({ type: 'boolean', default: true })
|
// @Column({ type: 'boolean', default: true })
|
||||||
isActive: boolean;
|
// isActive: boolean;
|
||||||
|
|
||||||
@Column({ type: 'boolean', default: false })
|
// @Column({ type: 'boolean', default: false })
|
||||||
isArchived: boolean;
|
// isArchived: boolean;
|
||||||
|
|
||||||
@CreateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
|
// @CreateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
|
||||||
createDateTime: Date;
|
// createDateTime: Date;
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 300 })
|
// @Column({ type: 'varchar', length: 300 })
|
||||||
createdBy: string;
|
// createdBy: string;
|
||||||
|
|
||||||
@UpdateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
|
// @UpdateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
|
||||||
lastChangedDateTime: Date;
|
// lastChangedDateTime: Date;
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 300 })
|
// @Column({ type: 'varchar', length: 300 })
|
||||||
lastChangedBy: string;
|
// lastChangedBy: string;
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 300, nullable: true })
|
// @Column({ type: 'varchar', length: 300, nullable: true })
|
||||||
internalComment: string | null;
|
// 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 { Entity, Column } from 'typeorm';
|
||||||
import { BaseEntity } from './base.entity.js';
|
import { BaseEntity } from './base.entity.js';
|
||||||
|
|
||||||
@Entity({ name: 'item' })
|
@Entity({ name: 'user' })
|
||||||
export class Item extends BaseEntity {
|
export class User extends BaseEntity {
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 300 })
|
@Column({ type: 'varchar', length: 300 , nullable: true})
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 300 })
|
@Column({ type: 'varchar', length: 300 , nullable: true})
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<form id="loginForm" method="post" name="login" action="/api/login" class ="loginForm">
|
<form id="loginForm" method="post" name="login" action="/api/login" class ="loginForm">
|
||||||
<p class="loginHere">Login Here</p>
|
<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">
|
<input type="text" name="password" placeholder="password">
|
||||||
<button class="submit" onclick="login()">LOGIN</button>
|
<button class="submit" onclick="login()">LOGIN</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user