forked from VitorCarvalho67/Boot
-
Notifications
You must be signed in to change notification settings - Fork 0
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 VitorCarvalho67#115 from Daniel-Alvarenga/main
Fix empresa aluno messages sockets
- Loading branch information
Showing
7 changed files
with
103 additions
and
25 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
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 |
---|---|---|
@@ -1,29 +1,51 @@ | ||
import { Server, Socket } from 'socket.io'; | ||
import { validateTokenAluno } from '../../middleware/auth/socket'; | ||
|
||
interface dataDTO{ | ||
message:{ | ||
conteudo: string, | ||
email: string, | ||
identifier: string, | ||
}, | ||
authorization: string | ||
import { | ||
validateTokenAluno, | ||
validateTokenEmpresa, | ||
validateTokenProfessor, | ||
} from '../../middleware/auth/socket'; | ||
|
||
import { IdentificadorEnum } from '../../modules/interfaces/sharedDTOs'; | ||
|
||
interface dataDTO { | ||
message: { | ||
conteudo: string; | ||
email: string; | ||
identifier: string; | ||
}; | ||
sender: string; | ||
authorization: string; | ||
} | ||
|
||
export const sendMessage = async (io: Server, socket: Socket, data: dataDTO) => { | ||
try { | ||
const token = data.authorization; | ||
const decoded = await validateTokenAluno(token); | ||
|
||
let decoded = await validateTokenAluno(token) as any; | ||
|
||
if (!decoded) { | ||
let decoded = await validateTokenEmpresa(token) as any; | ||
|
||
if (!decoded) { | ||
let decoded = await validateTokenProfessor(token) as any; | ||
|
||
if (!decoded) { | ||
console.log('Token inválido para enter-vinculo-aluno'); | ||
// socket.emit('error', { message: 'Invalid token' }); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
|
||
if (!decoded) { | ||
console.log('Token inválido para vinculo-update'); | ||
// socket.emit('error', { message: 'Invalid token' }); | ||
console.log('Token inválido para sendMessage'); | ||
return; | ||
} | ||
|
||
console.log('Nova mensagem para: ' + data.message.email); | ||
io.to(data.message.email).emit('new-message', data.message); | ||
} catch (error) { | ||
console.log('Erro em vinculo-update handler:', error); | ||
console.log('Erro em sendMessage handler:', error); | ||
} | ||
}; | ||
}; |
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