Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
kfet/sockets/add/addUser.js

28 lines
845 B
JavaScript
Raw Normal View History

2020-05-31 22:47:20 +02:00
const models = require("../../models");
module.exports = socket => {
return async (data) => {
try {
try {
await models.User.create({
username: data.username,
firstName: data.firstName,
lastName: data.lastName,
passwordHash: data.password ? data.password : null
});
socket.emit("add user", data.username);
socket.broadcast.emit("add user", data.username);
} catch (e) {
if (e instanceof models.Sequelize.ValidationError)
socket.emit("fail add user");
else
throw e;
}
} catch (e) {
socket.emit("internal error");
console.error(e);
}
}
}