Skip to content
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

fix: Change the npm registry to the Taobao registry in the Dockerfile. #155

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6b5b180
feat(teach-frontend): init
cuixiaorui Jun 10, 2023
25f51b5
feat(teach-frontend): 03-测试第一个组件 TheHeader - 测试 useRouter 的策略
cuixiaorui Jun 10, 2023
4daa9eb
chore: add build before start docker
cuixiaorui Jun 12, 2023
2ec3c3a
test: refactor search tasks
cuixiaorui Jun 13, 2023
2b2c587
feat(back-end): unify the returned data format
cuixiaorui Jun 14, 2023
3e6b06f
feat(front-end): handle response data
cuixiaorui Jun 14, 2023
3a6713a
feat(front-end): add task response type
cuixiaorui Jun 14, 2023
64a7614
feat(front-end): add project response type
cuixiaorui Jun 14, 2023
44c3f58
refactor: handle task mock type
cuixiaorui Jun 14, 2023
81140a9
refactor: type
cuixiaorui Jun 14, 2023
2943fe2
feat: support jump to task
cuixiaorui Jun 14, 2023
c6e6edf
feat: completed list sort
cuixiaorui Jun 14, 2023
e75df82
refactor: select left list status
cuixiaorui Jun 15, 2023
8114f6f
feat(teach-frontend): sync frontend code
cuixiaorui Jun 16, 2023
bca66f2
feat: sync frontend
cuixiaorui Jun 16, 2023
b406022
chore: update
cuixiaorui Jun 16, 2023
854f527
feat(teach-frontend): 04&05-测试 useRouter 的最佳测试&重构test helper
cuixiaorui Jun 16, 2023
801c8b7
refactor: test setup router mock
cuixiaorui Jun 16, 2023
e6a53ad
refactor: add const
cuixiaorui Jun 17, 2023
3370b82
refactor: command
cuixiaorui Jun 18, 2023
c904340
feat(teach-frontend): 06-测试 window.open 的方式&重构整理 theHeader
cuixiaorui Jun 18, 2023
8979f6c
refactor(frontend): command
cuixiaorui Jun 20, 2023
1130c06
refactor: theHeader
cuixiaorui Jun 20, 2023
d2248e8
chore: add sync frentend script
cuixiaorui Jun 20, 2023
16c3f61
chore: sync frontend
cuixiaorui Jun 20, 2023
7a36264
refactor: search test
cuixiaorui Jun 29, 2023
848d160
chore: sync frontend
cuixiaorui Jun 30, 2023
0a77779
feat(teach-frontend): 08-测试 commandModal & 键盘事件
cuixiaorui Jul 2, 2023
1392644
feat(teach-frontend): 09-测试 search & timer & promise & 独居测试
cuixiaorui Jul 3, 2023
ae1408f
refactor: command test case
cuixiaorui Jul 3, 2023
e437a52
feat(teach-frontend): 10-测试 searchTasks & 测试 pinia
cuixiaorui Jul 4, 2023
4fb88d7
feat(teach-frontend): 11-测试 searchCommands
cuixiaorui Jul 5, 2023
c9eac9c
feat(teach-frontend): 12-群居测试 search 功能
cuixiaorui Jul 6, 2023
61f2700
refactor: command test case
cuixiaorui Jul 6, 2023
f1322a2
test: add test case for task store
cuixiaorui Jul 7, 2023
38cf1e4
chore: add test coverage
cuixiaorui Jul 7, 2023
9961279
refactor: search tasks test case
cuixiaorui Jul 7, 2023
2efe2b6
fix: Change the npm registry to the Taobao registry in the Dockerfile.
Jul 8, 2023
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
2 changes: 1 addition & 1 deletion apps/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY package*.json ./

# 安装依赖
RUN npm install -g pnpm@7.17.0
Run pnpm install --prod
Run pnpm install --prod --registry https://registry.npm.taobao.org

# 复制项目文件到工作目录
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"docker:start": "docker-compose up --build"
"docker:start": "npm run build && docker-compose up --build"
},
"dependencies": {
"@nestjs/common": "^9.3.5",
Expand Down
14 changes: 13 additions & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Module } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { ConfigModule } from '@nestjs/config'
import { APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { TasksModule } from './tasks/tasks.module'
import { ProjectsModule } from './projects/projects.module'
import { HttpExceptionFilter } from './core/filter/http-exception/http-exception.filter'
import { TransformInterceptor } from './core/interceptor/transform/transform.interceptor'

@Module({
imports: [
Expand All @@ -17,7 +20,16 @@ import { ProjectsModule } from './projects/projects.module'
MongooseModule.forRoot(process.env.MONGODB_URL),
],
controllers: [AppController],
providers: [AppService],
providers: [
{
provide: APP_FILTER,
useClass: HttpExceptionFilter,
},
{
provide: APP_INTERCEPTOR,
useClass: TransformInterceptor,
},
AppService],
})

export class AppModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { HttpExceptionFilter } from './http-exception.filter'

describe('HttpExceptionFilter', () => {
it('should be defined', () => {
expect(new HttpExceptionFilter()).toBeDefined()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common'

@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter {
catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp()
const response = ctx.getResponse()
const status = exception.getStatus()

const message = exception.message
? exception.message
: `${status >= 500 ? 'Service Error' : 'Client Error'}`

const errorResponse = {
data: {},
message,
code: -1,
}

response.status(status)
response.header('Content-Type', 'application/json; charset=utf-8')
response.send(errorResponse)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TransformInterceptor } from './transform.interceptor'

describe('TransformInterceptor', () => {
it('should be defined', () => {
expect(new TransformInterceptor()).toBeDefined()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'
import { Observable, map } from 'rxjs'

@Injectable()
export class TransformInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
map((data) => {
return {
data,
code: 0,
msg: 'Request successful',
}
}),
)
}
}
2 changes: 1 addition & 1 deletion apps/backend/src/projects/schemas/project.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Document } from 'mongoose'

export type ProjectDocument = Project & Document

@Schema({ timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' } })
@Schema({ timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' } })
export class Project {
@Prop({ required: true })
name: string
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tasks/schemas/task.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Project } from '../../projects/schemas/project.schema'

export type TaskDocument = Task & Document

@Schema({ timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' } })
@Schema({ timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' } })
export class Task {
@Prop({ required: true })
title: string
Expand Down
23 changes: 18 additions & 5 deletions apps/backend/src/tasks/tasks.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common'
import {
Body,
Controller,
Delete,
Get,
Param,
Patch,
Post,
Query,
} from '@nestjs/common'
import { TasksService } from './tasks.service'
import { Task } from './schemas/task.schema'
import { CreateTaskDto } from './dto/create-task.dto'
Expand All @@ -14,8 +23,12 @@ export class TasksController {
}

@Get()
findAll(@Query('projectId') projectId?: string, @Query('status') status?: string) {
return this.tasksService.findAll(projectId, status)
findAll(
@Query('projectId') projectId?: string,
@Query('status') status?: string,
@Query('sortBy') sortBy?: string,
) {
return this.tasksService.findAll(projectId, status, sortBy)
}

@Get(':id')
Expand All @@ -30,8 +43,8 @@ export class TasksController {

@Patch(':id')
async update(
@Param('id') id: string,
@Body() updateTaskDto: UpdateTaskDto,
@Param('id') id: string,
@Body() updateTaskDto: UpdateTaskDto,
): Promise<Task> {
return this.tasksService.update(id, updateTaskDto)
}
Expand Down
17 changes: 14 additions & 3 deletions apps/backend/src/tasks/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class TasksService {
return createdTask.save()
}

async findAll(projectId?: string, status?: string): Promise<Task[]> {
async findAll(
projectId?: string,
status?: string,
sortBy = 'position',
): Promise<Task[]> {
const query: {
projectId?: Types.ObjectId
status?: string
Expand All @@ -33,7 +37,10 @@ export class TasksService {
if (status)
query.status = status

return this.taskModel.find(query).sort({ position: -1 }).exec()
return this.taskModel
.find(query)
.sort({ [sortBy]: -1 })
.exec()
}

async findOne(id: string): Promise<Task> {
Expand All @@ -51,7 +58,11 @@ export class TasksService {
update.projectId = new Types.ObjectId(updateTaskDto.projectId)

const updatedTask = await this.taskModel
.findByIdAndUpdate(id, { $set: { ...updateTaskDto, ...update } }, { new: true })
.findByIdAndUpdate(
id,
{ $set: { ...updateTaskDto, ...update } },
{ new: true },
)
.exec()

if (!updatedTask)
Expand Down
2 changes: 2 additions & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
"@iconify-json/carbon": "^1.1.13",
"@iconify-json/mdi": "^1.1.41",
"@iconify/vue": "^4.0.2",
"@pinia/testing": "^0.1.2",
"@types/lodash-es": "^4.17.6",
"@unocss/reset": "^0.48.3",
"@vitejs/plugin-vue": "^4.0.0",
"@vitejs/plugin-vue-jsx": "^3.0.0",
"@vitest/coverage-c8": "^0.28.4",
"@vue/test-utils": "^2.2.10",
"@vueuse/core": "^9.10.0",
"cross-env": "^7.0.3",
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script setup lang="ts">
import { NConfigProvider } from 'naive-ui'
import BaseLayout from './layout/BaseLayout.vue'
import { useCommand } from '@/composables/command'
import { useThemeStore } from '@/store'

const themeStore = useThemeStore()
const { initCommands } = useCommand()
initCommands()
</script>

<template>
Expand Down
12 changes: 10 additions & 2 deletions apps/frontend/src/api/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ export const http: AxiosInstance = axios.create({

http.interceptors.response.use(
(response: AxiosResponse) => {
return response.data // Directly extract data from the response
const { code, message, data } = response.data

if (code === 0) {
return data
}
else {
console.error(message)
return Promise.reject(new Error(message))
}
},
(error) => {
// Handle common error logic here if needed
console.error('Request error:', error)
return Promise.reject(error)
},
)
5 changes: 3 additions & 2 deletions apps/frontend/src/api/projects.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { http } from './http'
import type { ProjectResponse } from './types'

export function fetchAllProjects() {
return http.get('/projects')
return http.get<ProjectResponse[], ProjectResponse[]>('/projects')
}

export function fetchCreateProject(name: string) {
return http.post('/projects', {
return http.post<ProjectResponse, ProjectResponse>('/projects', {
name,
})
}
23 changes: 12 additions & 11 deletions apps/frontend/src/api/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
import { http } from './http'
import type { TaskResponse } from './types'
import type { Task } from '@/store'
import { TaskStatus } from '@/store'

export function fetchAllTasks({ pId, status }: { pId?: string; status?: TaskStatus }) {
return http.get('/tasks', {
export function fetchAllTasks({ pId, status, sortBy }: { pId?: string; status?: TaskStatus; sortBy?: string }) {
return http.get<TaskResponse[], TaskResponse[]>('/tasks', {
params: {
projectId: pId,
status,
sortBy,
},
})
}

export function fetchCreateTask(title: string, pId: string) {
return http.post('/tasks', {
return http.post<TaskResponse, TaskResponse>('/tasks', {
title,
projectId: pId,
})
}

export function fetchUpdateTaskTitle(taskId: Task['id'], title: string) {
return http.patch(`/tasks/${taskId}`, {
return http.patch<TaskResponse>(`/tasks/${taskId}`, {
title,
})
}
export function fetchUpdateTaskContent(taskId: Task['id'], content: string) {
return http.patch(`/tasks/${taskId}`, {
return http.patch<TaskResponse>(`/tasks/${taskId}`, {
content,
})
}

export function fetchCompleteTask(taskId: Task['id']) {
return http.patch(`/tasks/${taskId}`, {
return http.patch<TaskResponse>(`/tasks/${taskId}`, {
status: TaskStatus.COMPLETED,
})
}

export function fetchRestoreTask(taskId: Task['id']) {
return http.patch(`/tasks/${taskId}`, {
return http.patch<TaskResponse>(`/tasks/${taskId}`, {
status: TaskStatus.ACTIVE,
})
}

export function fetchMoveTaskToProject(taskId: Task['id'], projectId: string) {
return http.patch(`/tasks/${taskId}`, {
return http.patch<TaskResponse>(`/tasks/${taskId}`, {
projectId,
})
}

export function fetchRemoveTask(taskId: Task['id']) {
return http.patch(`/tasks/${taskId}`, {
return http.patch<TaskResponse>(`/tasks/${taskId}`, {
status: TaskStatus.REMOVED,
})
}

export function fetchUpdateTaskPosition(taskId: Task['id'], position: number) {
return http.patch(`/tasks/${taskId}`, {
return http.patch<TaskResponse>(`/tasks/${taskId}`, {
position,
})
}
19 changes: 19 additions & 0 deletions apps/frontend/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { TaskStatus } from '@/store/tasks'

export interface TaskResponse {
title: string
content: string
status: TaskStatus
projectId: string
position: number
_id: string
createdAt: string
updatedAt: string
}

export interface ProjectResponse {
createdAt: string
name: string
updatedAt: string
_id: string
}
7 changes: 5 additions & 2 deletions apps/frontend/src/components/command/CommandModal.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script setup lang="ts">
import { NModal } from 'naive-ui'
import { watch } from 'vue'
import { resetSearch } from './search'
import { useSearch } from './search'
import CommandBody from './CommandModalBody.vue'
import { registerKeyboardShortcut, showCommandModal } from './commandModal'
import { useCommandModal } from './commandModal'

const { resetSearch } = useSearch()
const { registerKeyboardShortcut, showCommandModal } = useCommandModal()

registerKeyboardShortcut()

Expand Down
Loading