Skip to content

Commit

Permalink
fix: optimize entity name
Browse files Browse the repository at this point in the history
  • Loading branch information
WittBulter committed Feb 20, 2019
1 parent 17f86a9 commit cae4b05
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
7 changes: 3 additions & 4 deletions app/controllers/sessions.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sessions } from '../entities'
import { Body, Get, JsonController, Post, QueryParam, UseInterceptor } from 'routing-controllers'
import { SessionsService } from '../services'
import { Interceptors } from '../helpers'
import { Body, Get, JsonController, Post, QueryParam, UseInterceptor } from 'routing-controllers'
import { Session } from '../entities'


@JsonController()
Expand All @@ -12,15 +12,14 @@ export class SessionsController {
) {
}


@Get('/sessions')
@UseInterceptor(Interceptors.MessageInterceptor)
async session(@QueryParam('username') username: string): Promise<any> {
return 'hello'
}

@Post('/sessions')
async create(@Body() session: Sessions): Promise<any> {
async create(@Body() session: Session): Promise<any> {
const created = await this.sessionsService.create(session)
return { message: 'ok', created }
}
Expand Down
4 changes: 2 additions & 2 deletions app/entities/sessions.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
* How to auto validaing? see: https://github.com/typestack/routing-controllers#auto-validating-action-params
*/

@Entity()
export class Sessions extends BaseEntity {
@Entity('sessions')
export class Session extends BaseEntity {

@ObjectIdColumn()
id: string
Expand Down
10 changes: 5 additions & 5 deletions app/services/sessions.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { EntityManager, getMongoRepository, MongoRepository } from 'typeorm'
import { getMongoRepository, MongoRepository } from 'typeorm'
import { Service } from 'typedi'
import { Sessions } from '../entities'
import { Session } from '../entities'

@Service()
export class SessionsService {
repository: MongoRepository<Sessions>
repository: MongoRepository<Session>

constructor() {
this.repository = getMongoRepository(Sessions)
this.repository = getMongoRepository(Session)
}

async create(session: Sessions): Promise<Sessions> {
async create(session: Session): Promise<Session> {
return await this.repository.save(session)
}

Expand Down
5 changes: 3 additions & 2 deletions config/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import * as Koa from 'koa'
import * as controllers from '../app/controllers'
import * as interceptors from './interceptors'
import { Container } from 'typedi'
import { useKoaServer, useContainer } from 'routing-controllers'
import { useMiddlewares } from './middlewares'
import './connection'
import { useKoaServer, useContainer } from 'routing-controllers'

// import './connection'

const objectToArray = (dict: object): Array<any> =>
Object.keys(dict).map(name => dict[name])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koa2-typescript-guide",
"version": "0.1.1",
"version": "0.1.2",
"description": "the best practice of building Koa2 with TypeScript",
"main": "app.ts",
"scripts": {
Expand Down

0 comments on commit cae4b05

Please sign in to comment.