-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Construct database, controller and service. 2. Remove config in webpack.config.js. 3. Adjust frontend and backend code accordingly.
- Loading branch information
1 parent
ef99e59
commit 9073042
Showing
21 changed files
with
1,326 additions
and
192 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
|
||
import { ConfigModule } from '@nestjs/config'; | ||
import { dataBaseConfig } from '../app/database/database.config'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { TaskModule } from './task/task.module'; | ||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
imports: [ | ||
ConfigModule.forRoot(), | ||
SequelizeModule.forRoot(dataBaseConfig), | ||
TaskModule, | ||
], | ||
}) | ||
export class AppModule {} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { SequelizeModuleOptions } from '@nestjs/sequelize'; | ||
import { join } from 'path'; | ||
import { cwd } from 'process'; | ||
import { SequelizeOptions } from 'sequelize-typescript'; | ||
|
||
function getDatabaseConfig(): Partial< | ||
{ | ||
name?: string; | ||
retryAttempts?: number; | ||
retryDelay?: number; | ||
autoLoadModels?: boolean; | ||
synchronize?: boolean; | ||
uri?: string; | ||
} & Partial<SequelizeOptions> | ||
> { | ||
return { | ||
dialect: 'sqlite', | ||
storage: join(cwd(), 'database.sqlite'), | ||
autoLoadModels: true, | ||
synchronize: true, | ||
}; | ||
} | ||
|
||
export const dataBaseConfig: SequelizeModuleOptions = getDatabaseConfig(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class CreateTaskDto { | ||
id: string; | ||
text: string; | ||
day: string; | ||
reminder: boolean; | ||
createdAt?: Date; | ||
updatedAt?: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
import { CreateTaskDto } from './create-task.dto'; | ||
|
||
export class UpdateTaskDto extends PartialType(CreateTaskDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Column, Table, Model, PrimaryKey } from 'sequelize-typescript'; | ||
|
||
@Table({ tableName: 'Tasks' }) | ||
export class Task extends Model { | ||
@PrimaryKey | ||
@Column | ||
id: string; | ||
@Column | ||
text: string; | ||
@Column | ||
day: string; | ||
@Column | ||
reminder: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Param, | ||
Post, | ||
Put, | ||
} from '@nestjs/common'; | ||
import { TaskService } from './task.service'; | ||
import { CreateTaskDto } from './dto/create-task.dto'; | ||
|
||
@Controller('tasks') | ||
export class TaskController { | ||
constructor(private taskService: TaskService) {} | ||
|
||
@Get('') | ||
async getTasks() { | ||
return await this.taskService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
async getTask(id: string) { | ||
return await this.taskService.findOne(id); | ||
} | ||
|
||
@Post('/create') | ||
async createTask(@Body() task: CreateTaskDto) { | ||
return await this.taskService.create(task); | ||
} | ||
|
||
@Put(':id') | ||
async updateTask(@Body() task: CreateTaskDto) { | ||
return await this.taskService.update(task.id, task); | ||
} | ||
|
||
@Delete(':id') | ||
async deleteTask(@Param('id') id: string) { | ||
return await this.taskService.remove(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TaskService } from './task.service'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { Task } from './entities/task.entity'; | ||
import { TaskController } from './task.controller'; | ||
|
||
@Module({ | ||
imports: [SequelizeModule.forFeature([Task])], | ||
controllers: [TaskController], | ||
providers: [TaskService], | ||
exports: [SequelizeModule.forFeature([Task]), TaskService], | ||
}) | ||
export class TaskModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateTaskDto } from './dto/create-task.dto'; | ||
import { UpdateTaskDto } from './dto/update-task.dto'; | ||
import { Task } from './entities/task.entity'; | ||
import { InjectModel } from '@nestjs/sequelize'; | ||
|
||
@Injectable() | ||
export class TaskService { | ||
constructor( | ||
@InjectModel(Task) | ||
private taskRepository: typeof Task | ||
) {} | ||
|
||
async create(createTaskDto: CreateTaskDto): Promise<Task> { | ||
return await this.taskRepository.create(createTaskDto as any); | ||
} | ||
|
||
async findAll() { | ||
return await this.taskRepository.findAll(); | ||
} | ||
|
||
async findOne(id: string) { | ||
return await this.taskRepository.findOne({ where: { id: id } }); | ||
} | ||
|
||
async update(id: string, updateTaskDto: UpdateTaskDto) { | ||
return await this.taskRepository.update( | ||
{ | ||
text: updateTaskDto.text, | ||
day: updateTaskDto.day, | ||
reminder: updateTaskDto.reminder, | ||
}, | ||
{ where: { id: id } } | ||
); | ||
} | ||
|
||
async remove(id: string) { | ||
return await this.taskRepository.destroy({ where: { id: id } }); | ||
} | ||
|
||
async removeByName(name: string) { | ||
return await this.taskRepository.destroy({ | ||
where: { title: name }, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,8 @@ | ||
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin'); | ||
const { join } = require('path'); | ||
const { composePlugins, withNx } = require('@nx/webpack'); | ||
|
||
module.exports = { | ||
output: { | ||
path: join(__dirname, '../dist/nest-backend'), | ||
}, | ||
plugins: [ | ||
new NxAppWebpackPlugin({ | ||
target: 'node', | ||
compiler: 'tsc', | ||
main: './src/main.ts', | ||
tsConfig: './tsconfig.app.json', | ||
assets: ['./src/assets'], | ||
optimization: false, | ||
outputHashing: 'none', | ||
}), | ||
], | ||
}; | ||
// Nx plugins for webpack. | ||
module.exports = composePlugins(withNx(), (config) => { | ||
// Update the webpack config as needed here. | ||
// e.g. `config.plugins.push(new MyPlugin())` | ||
return config; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export interface Task { | ||
id?: number; | ||
id: string; | ||
text: string; | ||
day: string; | ||
reminder: boolean; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.