Skip to content

Commit

Permalink
refactor: use explanatory variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucky3028 committed Oct 4, 2023
1 parent 1338dcc commit 53cfb43
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
18 changes: 12 additions & 6 deletions apps/auto-run-ac-api/src/api/defaultTriggersApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export const defaultTriggersApi = app
.onConflictDoNothing()
.returning({ createdId: table.id });

if (createdTriggers.length === 0) {
const isConflicted = createdTriggers.length === 0;
if (isConflicted) {
return emptyJsonT(c, 409);
}

Expand Down Expand Up @@ -160,7 +161,8 @@ export const defaultTriggersApi = app
.where(eq(table.id, id))
.returning({ updatedId: table.id });

if (updatedTriggers.length === 0) {
const isTriggerNotFound = updatedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand Down Expand Up @@ -200,7 +202,8 @@ export const defaultTriggersApi = app
.where(eq(table.id, id))
.returning({ updatedId: table.id });

if (updatedTriggers.length === 0) {
const isTriggerNotFound = updatedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand Down Expand Up @@ -240,7 +243,8 @@ export const defaultTriggersApi = app
.where(eq(table.id, id))
.returning({ updatedId: table.id });

if (updatedTriggers.length === 0) {
const isTriggerNotFound = updatedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand Down Expand Up @@ -280,7 +284,8 @@ export const defaultTriggersApi = app
.where(eq(table.id, id))
.returning({ updatedId: table.id });

if (updatedTriggers.length === 0) {
const isTriggerNotFound = updatedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand All @@ -307,7 +312,8 @@ export const defaultTriggersApi = app
const { id } = c.req.valid('param');
const deletedTriggers = await c.get('db').delete(table).where(eq(table.id, id)).returning({ deletedId: table.id });

if (deletedTriggers.length === 0) {
const isTriggerNotFound = deletedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand Down
20 changes: 13 additions & 7 deletions apps/auto-run-ac-api/src/api/triggersApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const triggersApi = app
const contents = c.req.valid('json');

const id = nanoid();
const createdTrigger = await c
const createdTriggers = await c
.get('db')
.insert(table)
.values({
Expand All @@ -79,7 +79,8 @@ export const triggersApi = app
.onConflictDoNothing()
.returning({ createdId: table.id });

if (createdTrigger.length === 0) {
const isConflicted = createdTriggers.length === 0;
if (isConflicted) {
return emptyJsonT(c, 409);
}

Expand Down Expand Up @@ -160,7 +161,8 @@ export const triggersApi = app
.where(eq(table.id, id))
.returning({ updatedId: table.id });

if (updatedTriggers.length === 0) {
const isTriggerNotFound = updatedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand Down Expand Up @@ -200,7 +202,8 @@ export const triggersApi = app
.where(eq(table.id, id))
.returning({ updatedId: table.id });

if (updatedTriggers.length === 0) {
const isTriggerNotFound = updatedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand Down Expand Up @@ -240,7 +243,8 @@ export const triggersApi = app
.where(eq(table.id, id))
.returning({ updatedId: table.id });

if (updatedTriggers.length === 0) {
const isTriggerNotFound = updatedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand Down Expand Up @@ -280,7 +284,8 @@ export const triggersApi = app
.where(eq(table.id, id))
.returning({ updatedId: table.id });

if (updatedTriggers.length === 0) {
const isTriggerNotFound = updatedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand All @@ -307,7 +312,8 @@ export const triggersApi = app
const { id } = c.req.valid('param');
const deletedTriggers = await c.get('db').delete(table).where(eq(table.id, id)).returning({ deletedId: table.id });

if (deletedTriggers.length === 0) {
const isTriggerNotFound = deletedTriggers.length === 0;
if (isTriggerNotFound) {
return emptyJsonT(c, 404);
}

Expand Down

0 comments on commit 53cfb43

Please sign in to comment.