From 42778ef8895a7f42bb83971929a8c49a295e504a Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 27 Oct 2024 11:34:40 +0100 Subject: [PATCH] refacto: less if in if --- src/data/data.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/data/data.ts b/src/data/data.ts index b8f4211..444e076 100644 --- a/src/data/data.ts +++ b/src/data/data.ts @@ -43,12 +43,15 @@ class Data { model: T ): Promise { try { - if (model._id) { - const oldModel = await this.get(model._id) - if (oldModel) { - const result = await this.locale?.put({ ...oldModel, ...model }) - return result?.ok ?? false - } + if (!model._id) { + const result = await this.locale?.put(model) + return result?.ok ?? false + } + + const oldModel = await this.get(model._id) + if (oldModel) { + const result = await this.locale?.put({ ...oldModel, ...model }) + return result?.ok ?? false } const result = await this.locale?.put(model)