Skip to content

Commit

Permalink
fix messages findOne (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
an-lee authored Feb 22, 2024
1 parent 086d4fa commit 74e061c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
4 changes: 3 additions & 1 deletion enjoy/src/main/db/handlers/messages-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import log from "electron-log/main";
import { t } from "i18next";
import db from "@main/db";

const logger = log.scope("messages-handler");
class MessagesHandler {
private async findAll(
event: IpcMainEvent,
Expand Down Expand Up @@ -47,6 +48,7 @@ class MessagesHandler {
association: "speeches",
model: Speech,
where: { sourceType: "Message" },
required: false,
},
],
where: {
Expand All @@ -57,7 +59,7 @@ class MessagesHandler {
return message?.toJSON();
})
.catch((err) => {
log.error(err);
logger.error(err);
event.sender.send("on-notification", {
type: "error",
message: err.message,
Expand Down
34 changes: 17 additions & 17 deletions enjoy/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
}) => {
return ipcRenderer.invoke("audios-find-all", params);
},
findOne: (params: object) => {
findOne: (params: any) => {
return ipcRenderer.invoke("audios-find-one", params);
},
create: (uri: string, params?: object) => {
create: (uri: string, params?: any) => {
return ipcRenderer.invoke("audios-create", uri, params);
},
update: (id: string, params: object) => {
update: (id: string, params: any) => {
return ipcRenderer.invoke("audios-update", id, params);
},
destroy: (id: string) => {
Expand All @@ -208,13 +208,13 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
}) => {
return ipcRenderer.invoke("videos-find-all", params);
},
findOne: (params: object) => {
findOne: (params: any) => {
return ipcRenderer.invoke("videos-find-one", params);
},
create: (uri: string, params?: object) => {
create: (uri: string, params?: any) => {
return ipcRenderer.invoke("videos-create", uri, params);
},
update: (id: string, params: object) => {
update: (id: string, params: any) => {
return ipcRenderer.invoke("videos-update", id, params);
},
destroy: (id: string) => {
Expand All @@ -233,16 +233,16 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
}) => {
return ipcRenderer.invoke("recordings-find-all", params);
},
findOne: (params: object) => {
findOne: (params: any) => {
return ipcRenderer.invoke("recordings-find-one", params);
},
syncAll: () => {
return ipcRenderer.invoke("recordings-sync-all");
},
create: (params: object) => {
create: (params: any) => {
return ipcRenderer.invoke("recordings-create", params);
},
update: (id: string, params: object) => {
update: (id: string, params: any) => {
return ipcRenderer.invoke("recordings-update", id, params);
},
destroy: (id: string) => {
Expand Down Expand Up @@ -272,16 +272,16 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
},
},
conversations: {
findAll: (params: { where?: object; offset?: number; limit?: number }) => {
findAll: (params: { where?: any; offset?: number; limit?: number }) => {
return ipcRenderer.invoke("conversations-find-all", params);
},
findOne: (params: object) => {
findOne: (params: any) => {
return ipcRenderer.invoke("conversations-find-one", params);
},
create: (params: object) => {
create: (params: any) => {
return ipcRenderer.invoke("conversations-create", params);
},
update: (id: string, params: object) => {
update: (id: string, params: any) => {
return ipcRenderer.invoke("conversations-update", id, params);
},
destroy: (id: string) => {
Expand All @@ -303,11 +303,11 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
},
},
messages: {
findAll: (params: { where?: object; offset?: number; limit?: number }) => {
findAll: (params: { where?: any; offset?: number; limit?: number }) => {
return ipcRenderer.invoke("messages-find-all", params);
},
findOne: (params: object) => {
return ipcRenderer.invoke("messages-find-one", params);
findOne: (where: any) => {
return ipcRenderer.invoke("messages-find-one", where);
},
createInBatch: (messages: Partial<MessageType>[]) => {
return ipcRenderer.invoke("messages-create-in-batch", messages);
Expand Down Expand Up @@ -417,7 +417,7 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
get: (key: string) => {
return ipcRenderer.invoke("cache-objects-get", key);
},
set: (key: string, value: string | object, ttl?: number) => {
set: (key: string, value: string | any, ttl?: number) => {
return ipcRenderer.invoke("cache-objects-set", key, value, ttl);
},
delete: (key: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const AssistantMessageComponent = (props: {

const findOrCreateSpeech = async () => {
const msg = await EnjoyApp.messages.findOne({ id: message.id });
if (msg.speeches.length > 0) {
if (msg && msg.speeches.length > 0) {
setSpeech(msg.speeches[0]);
} else {
createSpeech();
Expand Down
2 changes: 1 addition & 1 deletion enjoy/src/types/enjoy-app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type EnjoyAppType = {
};
messages: {
findAll: (params: any) => Promise<MessageType[]>;
findOne: (params: any) => Promise<MessageType>;
findOne: (where: any) => Promise<MessageType>;
createInBatch: (messages: Partial<MessageType>[]) => Promise<void>;
destroy: (id: string) => Promise<void>;
createSpeech: (id: string, configuration?: any) => Promise<SpeechType>;
Expand Down

0 comments on commit 74e061c

Please sign in to comment.