Skip to content

Commit

Permalink
fix: set all user leave the room when start
Browse files Browse the repository at this point in the history
  • Loading branch information
yociduo committed May 18, 2020
1 parent e6d18bc commit b47c9e9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { getLogger } from 'log4js';
import { createKoaServer, useContainer as routingUseContainer } from 'routing-controllers';
import { createSocketServer, useContainer as socketUseContainer } from 'socket-controllers';
import { Container } from 'typedi';
import { useContainer as ormUseContainer, createConnection, getConnectionOptions } from 'typeorm';
import { useContainer as ormUseContainer, createConnection, getConnectionOptions, getManager, getConnection } from 'typeorm';
import { config } from './config';
import { decorators } from './decorator';
import { UserRoom } from './entity';
import './middleware/socket/AuthenitificationMiddleware';

const logger = getLogger('startup');
Expand Down Expand Up @@ -48,6 +49,15 @@ async function createServer() {
await createConnection(connectionOptions);
logger.info('TypeORM connection success');

const result = await getConnection()
.createQueryBuilder()
.update(UserRoom)
.set({ isLeft: true })
.where('isLeft is false')
.execute();

logger.info('Set `UserRoom`.`isLeft` to true: ', result.raw.affectedRows);

/**
* We create a new koa server instance.
* We could have also use useKoaServer here to attach controllers to an existing koa instance.
Expand Down

0 comments on commit b47c9e9

Please sign in to comment.