feat: recieve userId from socket

This commit is contained in:
karishmas6
2024-10-21 23:07:28 +05:30
parent e885b1f535
commit 9a439f70bc

View File

@@ -126,10 +126,12 @@ export class WorkflowGenerator {
* @private * @private
*/ */
private registerEventHandlers = (socket: Socket) => { private registerEventHandlers = (socket: Socket) => {
socket.on('save', async (fileName: string) => { socket.on('save', (data) => {
logger.log('debug', `Saving workflow ${fileName}`); console.log('Received data:', data);
await this.saveNewWorkflow(fileName) const { fileName, userId } = data;
}); logger.log('debug', `Saving workflow ${fileName} for user ID ${userId}`);
this.saveNewWorkflow(fileName, userId);
});
socket.on('new-recording', () => this.workflowRecord = { socket.on('new-recording', () => this.workflowRecord = {
workflow: [], workflow: [],
}); });
@@ -477,7 +479,7 @@ export class WorkflowGenerator {
* @param fileName The name of the file. * @param fileName The name of the file.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public saveNewWorkflow = async (fileName: string) => { public saveNewWorkflow = async (fileName: string, userId: number) => {
const recording = this.optimizeWorkflow(this.workflowRecord); const recording = this.optimizeWorkflow(this.workflowRecord);
try { try {
this.recordingMeta = { this.recordingMeta = {
@@ -489,6 +491,7 @@ export class WorkflowGenerator {
params: this.getParams() || [], params: this.getParams() || [],
} }
const robot = await Robot.create({ const robot = await Robot.create({
userId,
recording_meta: this.recordingMeta, recording_meta: this.recordingMeta,
recording: recording, recording: recording,
}); });
@@ -497,7 +500,7 @@ export class WorkflowGenerator {
} }
catch (e) { catch (e) {
const { message } = e as Error; const { message } = e as Error;
logger.log('warn', `Cannot save the file to the local file system`) logger.log('warn', `Cannot save the file to the local file system ${e}`)
} }
this.socket.emit('fileSaved'); this.socket.emit('fileSaved');
} }