-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Roger13579/dev
Dev
- Loading branch information
Showing
21 changed files
with
300 additions
and
1,479 deletions.
There are no files selected for viewing
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,8 +1,11 @@ | ||
FROM node:latest | ||
ENV TZ=Asia/Taipei | ||
RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone | ||
WORKDIR /app | ||
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
RUN npm run build | ||
RUN npm run swagger | ||
EXPOSE 3000 | ||
CMD ["npm","start"] |
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
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,26 @@ | ||
import { Request } from 'express'; | ||
import { BaseController } from './baseController'; | ||
import { CustomResponseType } from '../types/customResponseType'; | ||
import { ResponseObject } from '../utils/responseObject'; | ||
import { CreateGroupDto } from '../dto/createGroupDto'; | ||
import { GroupService } from '../service/groupService'; | ||
import { IGroup } from '../models/group'; | ||
|
||
export class GroupController extends BaseController { | ||
private readonly groupService = new GroupService(); | ||
|
||
public createGroup = async (req: Request): Promise<ResponseObject> => { | ||
this.paramVerify(req); | ||
const createGroupDto = new CreateGroupDto(req); | ||
const group = (await this.groupService.createGroup( | ||
createGroupDto, | ||
)) as IGroup; | ||
return this.formatResponse( | ||
CustomResponseType.OK_MESSAGE, | ||
CustomResponseType.OK, | ||
{ | ||
groupId: group.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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { parseDate } from '../utils/common'; | ||
import { Types } from 'mongoose'; | ||
import { GroupStatus, TCreateGroupReq } from '../types/group.type'; | ||
|
||
export class CreateGroupDto { | ||
private readonly userId: Types.ObjectId; | ||
private readonly title: string; | ||
private readonly theater: string; | ||
private readonly movieTitle: string; | ||
private readonly time: Date; | ||
private readonly amount: number; | ||
private readonly haveTicket: boolean; | ||
private readonly content?: string; | ||
private readonly status: string; | ||
|
||
constructor(req: TCreateGroupReq) { | ||
this.userId = new Types.ObjectId((req.user as any).id as string); | ||
this.title = req.body.title; | ||
this.theater = req.body.theater; | ||
this.movieTitle = req.body.movieTitle; | ||
this.time = parseDate('time', req.body.time.toString()) as Date; | ||
this.amount = req.body.amount; | ||
this.haveTicket = req.body.haveTicket; | ||
this.content = req.body.content; | ||
this.status = GroupStatus.ongoing; | ||
} | ||
} |
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,5 @@ | ||
import { Schema } from 'mongoose'; | ||
|
||
export interface BaseModel extends Document { | ||
id: Schema.Types.ObjectId; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { CreateGroupDto } from '../dto/createGroupDto'; | ||
import { GroupModel, IGroup } from '../models/group'; | ||
|
||
export class GroupRepository { | ||
public async createGroup(createGroupDto: CreateGroupDto): Promise<IGroup> { | ||
return GroupModel.create(new GroupModel(createGroupDto)); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { BaseRoute } from './baseRoute'; | ||
import { GroupController } from '../controller/groupController'; | ||
import { UserVerify } from '../middleware/userVerify'; | ||
import { CreateGroupPipe } from '../validator/createGroup.pipe'; | ||
|
||
export class GroupRoute extends BaseRoute { | ||
protected controller!: GroupController; | ||
|
||
constructor() { | ||
super(); | ||
this.initial(); | ||
} | ||
|
||
protected initial(): void { | ||
this.controller = new GroupController(); | ||
this.setRouters(); | ||
} | ||
|
||
protected setRouters(): void { | ||
this.router.post( | ||
'/v1/group', | ||
/** | ||
* #swagger.tags = ['Group'] | ||
* #swagger.summary = '建立揪團' | ||
*/ | ||
/* | ||
#swagger.parameters['obj'] ={ | ||
in:'body', | ||
description:'欲建立的揪團資料', | ||
schema:{ | ||
$ref:"#/definitions/CustomCreateGroupObj" | ||
} | ||
} | ||
*/ | ||
/** | ||
#swagger.responses[200] = { | ||
description: 'OK', | ||
schema: { | ||
$ref: '#/definitions/CreateGroupSuccess' } | ||
} | ||
*/ | ||
UserVerify, | ||
this.usePipe(CreateGroupPipe), | ||
this.responseHandler(this.controller.createGroup), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CustomResponseType } from '../types/customResponseType'; | ||
import { throwError } from '../utils/errorHandler'; | ||
import log4js from '../config/log4js'; | ||
import { CreateGroupDto } from '../dto/createGroupDto'; | ||
import { GroupRepository } from '../repository/groupRepository'; | ||
import { IGroup } from '../models/group'; | ||
const logger = log4js.getLogger(`GroupService`); | ||
|
||
export class GroupService { | ||
private readonly groupRepository: GroupRepository = new GroupRepository(); | ||
|
||
public async createGroup( | ||
createGroupDto: CreateGroupDto, | ||
): Promise<IGroup | void> { | ||
return this.groupRepository.createGroup(createGroupDto).catch((err) => { | ||
logger.error('create user error', err); | ||
throwError( | ||
CustomResponseType.INSERT_ERROR_MESSAGE, | ||
CustomResponseType.INSERT_ERROR, | ||
); | ||
}); | ||
} | ||
} |
Oops, something went wrong.