Skip to content

Commit cd9b855

Browse files
committed
Delete cards - converted to DB
Fixed bug with connect channel Co-authored-by: Jon Cruz <[email protected]> Co-authored-by: Elena Atencio <[email protected]> Co-authored-by: John Donato <[email protected]>
1 parent 5d29352 commit cd9b855

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

electron/routes/dashboard.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,48 @@ ipcMain.on('getApps', (message: IpcMainEvent) => {
186186
* @return Returns the new list of applications
187187
*/
188188
ipcMain.on('deleteApp', (message: IpcMainEvent, index) => {
189-
// Retrives file contents from settings.json
190-
const settings = JSON.parse(fs.readFileSync(settingsLocation).toString('utf8'));
191-
const userServices = settings[currentUser].services;
192189

193-
// Remove application from settings.json
194-
userServices.splice(index, 1);
190+
if (currentUser === 'guest') {
195191

196-
// Update settings.json with new list
197-
fs.writeFileSync(settingsLocation, JSON.stringify(settings, null, '\t'), {
198-
encoding: 'utf8',
199-
});
192+
// Retrives file contents from settings.json
193+
const settings = JSON.parse(fs.readFileSync(settingsLocation).toString('utf8'));
194+
const userServices = settings[currentUser].services;
195+
196+
// Remove application from settings.json
197+
userServices.splice(index, 1);
198+
199+
// Update settings.json with new list
200+
fs.writeFileSync(settingsLocation, JSON.stringify(settings, null, '\t'), {
201+
encoding: 'utf8',
202+
});
203+
204+
// Sync event - return new applications list
205+
message.returnValue = userServices.map((arr: string[]) => [arr[0], arr[1], arr[3], arr[4]]);
206+
}
200207

201-
// Sync event - return new applications list
202-
message.returnValue = userServices.map((arr: string[]) => [arr[0], arr[1], arr[3], arr[4]]);
208+
else {
209+
console.log('not guest')
210+
return User.findOne({ username: currentUser })
211+
.then((data) => {
212+
console.log('User found', data);
213+
const service = data.services[index];
214+
return User.findOneAndUpdate({ username: currentUser }, {
215+
$pull: {services: service}
216+
}, {new: true})
217+
.then((data) => {
218+
console.log('Service deleted', data);
219+
message.returnValue = data.services.map((arr)=> [...arr])
220+
})
221+
.catch((error) => {
222+
console.log(`addApp failed : ${error}`)
223+
})
224+
})
225+
.catch((error) => {
226+
console.log(`checkUser failed : ${error}`)
227+
// return false;
228+
})
229+
230+
}
203231
});
204232

205233
/**

electron/routes/data.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ ipcMain.on('connect', async (message: Electron.IpcMainEvent, username: string, i
8585
// We get index from sidebar container: which is the mapplication (DEMO)
8686
const [databaseType, URI] = [userDatabase[1], userDatabase[2]];
8787

88+
console.log('if guest, inputted URI here...', URI)
8889
// Connect to the proper database
8990
if (databaseType === 'MongoDB') await connectMongo(index,URI);
9091
if (databaseType === 'SQL') pool = await connectPostgres(index, URI);
9192

9293
// Currently set to a global variable
93-
currentDatabaseType = 'MongoDB';
94+
currentDatabaseType = databaseType;
9495

9596
message.sender.send('databaseConnected', 'connected!');
9697
// eslint-disable-next-line no-shadow
@@ -107,9 +108,9 @@ ipcMain.on('connect', async (message: Electron.IpcMainEvent, username: string, i
107108
ipcMain.on('servicesRequest', async (message: Electron.IpcMainEvent) => {
108109
try {
109110
let result: any;
110-
111+
111112
// Mongo Database
112-
if (currentDatabaseType === 'MongoDB') {
113+
if (currentDatabaseType === 'MongoDB' ) {
113114
// Get all documents from the services collection
114115
result = await ServicesModel.find();
115116
}

0 commit comments

Comments
 (0)