-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.js
127 lines (122 loc) · 3.81 KB
/
socket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const socket = require("socket.io-client")("http://localhost:3030");
const { User, Project, Container } = require("./models/user-model");
socket.on("newProjectSuccess", async data => {
const projects = await Project.findOne(
{ repoID: data.data.project.repoID },
async (error, project) => {
const hasDB = "hasDB" in data.data ? true : false;
if (error) {
return { error: error, project: null };
} else if (project) {
let returnVal = null;
let value =
project.status === "Initialized" && hasDB
? "Finished 1/2"
: project.status === "Finished 1/2" && hasDB
? "Built"
: project.status === "Initialized" && !hasDB
? "Built"
: "Error";
project.status = value;
await project.save((err, project) => {
if (error !== null) {
console.log("Error while updating project Container", err);
}
socket.emit(`repoID`, {
repoID: project.repoID,
status: project.status
});
socket.emit(`newProjectRegister`, data);
return project;
});
}
}
);
});
socket.on("newProjectReject", async data => {
//data={data,message}
const projects = await Project.findOne(
{ repoID: data.data.project.repoID },
async (error, project) => {
if (error) {
return { error: error, project: null };
} else if (project) {
let returnVal = null;
project.status = data.message;
await project.save((err, project) => {
console.log("In save", err, project);
if (error !== null) {
console.log("Error while updating project Container", err);
}
socket.emit(`repoID`, {
repoID: project.repoID,
status: project.status
});
return project;
});
}
}
);
});
socket.on("newProjectRegisterSuccess", async data => {
console.log("Register Success", JSON.stringify(data));
const projectData = data.data.project;
const projects = await Project.findOne(
{ repoID: projectData.repoID },
async (error, project) => {
const hasDB = "hasDB" in data.data ? true : false;
if (error) {
return { error: error, project: null };
} else if (project) {
let value =
project.status === "Finished 1/2" && hasDB
? "Registered 1/2"
: project.status === "Built" && hasDB
? "Registered"
: project.status === "Build" && !hasDB
? "Registered"
: "Error";
project.status = value;
await project.save((err, project) => {
if (error !== null) {
console.log("Error while updating project Container", err);
}
socket.emit(`repoID`, {
repoID: project.repoID,
status: project.status
});
return project;
});
}
}
);
// Adding container
});
socket.on("newProjectRegisterReject", async data => {
//data={data,message}
console.log("Register Reject", JSON.stringify(data));
const projectData = data.data.project;
const projects = await Project.findOne(
{ repoID: projectData.repoID },
async (error, project) => {
if (error) {
return { error: error, project: null };
} else if (project) {
let returnVal = null;
project.status = data.message;
await project.save((err, project) => {
console.log("In save", err, project);
if (error !== null) {
console.log("Error while updating project Container", err);
}
socket.emit(`repoID`, {
repoID: project.repoID,
status: project.status
});
return project;
});
}
}
);
});
module.exports = { socket };