mirror of https://github.com/status-im/codimd.git
Fix author creation in operationCallback might cause unique constraint validation error
This commit is contained in:
parent
ffa14cfeef
commit
7e191acbde
|
@ -652,17 +652,25 @@ function operationCallback(socket, operation) {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
userId = socket.request.user.id;
|
userId = socket.request.user.id;
|
||||||
if (!note.authors[userId]) {
|
if (!note.authors[userId]) {
|
||||||
models.Author.create({
|
models.Author.findOrCreate({
|
||||||
noteId: noteId,
|
where: {
|
||||||
userId: userId,
|
noteId: noteId,
|
||||||
color: user.color
|
userId: userId
|
||||||
}).then(function (author) {
|
},
|
||||||
note.authors[author.userId] = {
|
defaults: {
|
||||||
userid: author.userId,
|
noteId: noteId,
|
||||||
color: author.color,
|
userId: userId,
|
||||||
photo: user.photo,
|
color: user.color
|
||||||
name: user.name
|
}
|
||||||
};
|
}).spread(function (author, created) {
|
||||||
|
if (author) {
|
||||||
|
note.authors[author.userId] = {
|
||||||
|
userid: author.userId,
|
||||||
|
color: author.color,
|
||||||
|
photo: user.photo,
|
||||||
|
name: user.name
|
||||||
|
};
|
||||||
|
}
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
return logger.error('operation callback failed: ' + err);
|
return logger.error('operation callback failed: ' + err);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue