listo socket io
This commit is contained in:
parent
e74365c0ff
commit
255e51e2f0
@ -1,12 +1,10 @@
|
||||
import {
|
||||
SubscribeMessage,
|
||||
WebSocketGateway,
|
||||
OnGatewayInit,
|
||||
WebSocketServer,
|
||||
OnGatewayConnection,
|
||||
OnGatewayDisconnect,
|
||||
} from '@nestjs/websockets';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Socket, Server } from 'socket.io';
|
||||
|
||||
@WebSocketGateway({
|
||||
@ -18,22 +16,18 @@ export class AppGateway
|
||||
implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect
|
||||
{
|
||||
@WebSocketServer() server: Server;
|
||||
private logger: Logger = new Logger('AppGateway');
|
||||
|
||||
// @SubscribeMessage('msgToServer')
|
||||
// handleMessage(client: Socket, payload: string): void {
|
||||
// this.server.emit('msgToClient', payload);
|
||||
// }
|
||||
|
||||
afterInit(server: Server) {
|
||||
this.logger.log('Init');
|
||||
actualizarUsuario(id_usuario: number) {
|
||||
this.server.emit('actualizar-usuario', { id_usuario });
|
||||
}
|
||||
|
||||
handleDisconnect(client: Socket) {
|
||||
this.logger.log(`Client disconnected: ${client.id}`);
|
||||
actualizarOperador(id_institucion: number) {
|
||||
this.server.emit('actualizar-operador', { id_institucion });
|
||||
}
|
||||
|
||||
handleConnection(client: Socket, ...args: any[]) {
|
||||
this.logger.log(`Client connected: ${client.id}`);
|
||||
}
|
||||
afterInit(server: Server) {}
|
||||
|
||||
handleConnection(client: Socket, ...args: any[]) {}
|
||||
|
||||
handleDisconnect(client: Socket) {}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
// import { AppGateway } from './app.gateway';
|
||||
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { BcryptModule } from './bcrypt/bcrypt.module';
|
||||
@ -135,6 +134,5 @@ import { SoapClientModule } from './soap-client/soap-client.module';
|
||||
UsuarioModule,
|
||||
SoapClientModule,
|
||||
],
|
||||
// providers: [AppGateway],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
@ -16,6 +16,7 @@ import { MultaModule } from 'src/multa/multa.module';
|
||||
import { StatusModule } from '../status/status.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
import { UsuarioModule } from '../usuario/usuario.module';
|
||||
import { AppGateway } from '../app.gateway';
|
||||
@Module({
|
||||
imports: [
|
||||
EquipoModule,
|
||||
@ -34,7 +35,7 @@ import { UsuarioModule } from '../usuario/usuario.module';
|
||||
UsuarioModule,
|
||||
],
|
||||
controllers: [PrestamoController],
|
||||
providers: [PrestamoService],
|
||||
providers: [AppGateway, PrestamoService],
|
||||
exports: [PrestamoService],
|
||||
})
|
||||
export class PrestamoModule {}
|
||||
|
@ -27,6 +27,7 @@ import { OperadorService } from '../operador/operador.service';
|
||||
import { StatusService } from '../status/status.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
import { UsuarioService } from '../usuario/usuario.service';
|
||||
import { AppGateway } from '../app.gateway';
|
||||
|
||||
@Injectable()
|
||||
export class PrestamoService {
|
||||
@ -46,6 +47,7 @@ export class PrestamoService {
|
||||
private statusService: StatusService,
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
private usuarioService: UsuarioService,
|
||||
private appGateway: AppGateway,
|
||||
) {}
|
||||
|
||||
async cancelarOperador(
|
||||
@ -75,7 +77,12 @@ export class PrestamoService {
|
||||
),
|
||||
)
|
||||
.then((_) => this.repository.save(prestamo))
|
||||
.then((_) => ({ message: 'Se canceló correctamente este préstamo.' }));
|
||||
.then((_) => {
|
||||
this.appGateway.actualizarUsuario(prestamo.usuario.id_usuario);
|
||||
return {
|
||||
message: 'Se canceló correctamente este préstamo.',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async cancelarUsuario(id_prestamo: number) {
|
||||
@ -94,7 +101,14 @@ export class PrestamoService {
|
||||
return this.equipoService
|
||||
.update(prestamo.equipo)
|
||||
.then((_) => this.repository.save(prestamo))
|
||||
.then((_) => ({ message: 'Se canceló correctamente este préstamo.' }));
|
||||
.then((_) => {
|
||||
this.appGateway.actualizarOperador(
|
||||
prestamo.usuario.institucionCarrera.institucion.id_institucion,
|
||||
);
|
||||
return {
|
||||
message: 'Se canceló correctamente este préstamo.',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async create(
|
||||
@ -135,7 +149,6 @@ export class PrestamoService {
|
||||
// const horaMin = moment(
|
||||
// `${ahora.format('YYYY-MM-DD')} ${institucionDia.hora_inicio}`,
|
||||
// );
|
||||
|
||||
// if (!institucionDia.activo)
|
||||
// throw new ConflictException(
|
||||
// 'El día de hoy no se esta realizando préstamos de equipos.',
|
||||
@ -187,7 +200,13 @@ export class PrestamoService {
|
||||
.toDate(),
|
||||
}),
|
||||
),
|
||||
);
|
||||
)
|
||||
.then((prestamo) => {
|
||||
this.appGateway.actualizarOperador(
|
||||
prestamo.usuario.institucionCarrera.institucion.id_institucion,
|
||||
);
|
||||
return prestamo;
|
||||
});
|
||||
}
|
||||
|
||||
async desactivarPrestamos() {
|
||||
@ -208,7 +227,14 @@ export class PrestamoService {
|
||||
prestamos[i].equipo.status = await this.statusService.findById(1);
|
||||
await this.equipoService
|
||||
.update(prestamos[i].equipo)
|
||||
.then((_) => this.repository.save(prestamos[i]));
|
||||
.then((_) => this.repository.save(prestamos[i]))
|
||||
.then((prestamo) => {
|
||||
this.appGateway.actualizarOperador(
|
||||
prestamo.usuario.institucionCarrera.institucion
|
||||
.id_institucion,
|
||||
);
|
||||
this.appGateway.actualizarUsuario(prestamo.usuario.id_usuario);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -233,9 +259,13 @@ export class PrestamoService {
|
||||
return this.equipoService
|
||||
.update(prestamo.equipo)
|
||||
.then((_) => this.repository.save(prestamo))
|
||||
.then((_) => ({
|
||||
message: 'Se entregó el equipo de cómputo correctamente.',
|
||||
}));
|
||||
.then((_) => {
|
||||
this.appGateway.actualizarUsuario(prestamo.usuario.id_usuario);
|
||||
return {
|
||||
message: 'Se entregó el equipo de cómputo correctamente.',
|
||||
equipo: prestamo.equipo,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async findAll(filtros: {
|
||||
@ -448,9 +478,12 @@ export class PrestamoService {
|
||||
return this.equipoService
|
||||
.update(prestamo.equipo)
|
||||
.then((_) => this.repository.save(prestamo))
|
||||
.then((_) => ({
|
||||
message: 'Se regresó el equipo de cómputo correctamente.',
|
||||
}));
|
||||
.then((_) => {
|
||||
this.appGateway.actualizarUsuario(prestamo.usuario.id_usuario);
|
||||
return {
|
||||
message: 'Se regresó el equipo de cómputo.',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async regresarIdPrestamo(
|
||||
|
Loading…
Reference in New Issue
Block a user