-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
50 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
import { prismaClient } from 'service/prismaClient'; | ||
import { defineController } from './$relay'; | ||
|
||
export default defineController(() => ({ | ||
get: async () => ({ | ||
status: 200, | ||
body: { | ||
server: 'ok', | ||
db: await prismaClient.$queryRaw`SELECT CURRENT_TIMESTAMP;`.then(() => 'ok' as const), | ||
}, | ||
}), | ||
get: () => ({ status: 200, body: { server: 'ok' } }), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
import type { Prisma } from '@prisma/client'; | ||
import type { TaskEntity } from 'api/@types/task'; | ||
import type { TaskDeleteVal } from '../model/taskEntity'; | ||
|
||
export let taskStorage: TaskEntity[] = []; | ||
|
||
export const taskCommand = { | ||
save: async (tx: Prisma.TransactionClient, task: TaskEntity): Promise<void> => { | ||
await tx.task.upsert({ | ||
where: { id: task.id }, | ||
update: { label: task.label, done: task.done }, | ||
create: { | ||
id: task.id, | ||
label: task.label, | ||
done: task.done, | ||
createdAt: new Date(task.createdTime), | ||
}, | ||
}); | ||
save: (task: TaskEntity): void => { | ||
taskStorage = taskStorage.some((t) => t.id === task.id) | ||
? taskStorage.map((t) => (t.id === task.id ? task : t)) | ||
: (taskStorage = [...taskStorage, task]); | ||
}, | ||
delete: async (tx: Prisma.TransactionClient, val: TaskDeleteVal): Promise<void> => { | ||
await tx.task.delete({ where: { id: val.deletableId } }); | ||
delete: (val: TaskDeleteVal): void => { | ||
taskStorage = taskStorage.filter((t) => t.id !== val.task.id); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
import type { Prisma, Task } from '@prisma/client'; | ||
import type { Maybe, TaskId } from 'api/@types/brandedId'; | ||
import type { TaskEntity } from 'api/@types/task'; | ||
import { taskIdParser } from 'service/idParsers'; | ||
|
||
const toModel = async (prismaTask: Task): Promise<TaskEntity> => ({ | ||
id: taskIdParser.parse(prismaTask.id), | ||
label: prismaTask.label, | ||
done: prismaTask.done, | ||
createdTime: prismaTask.createdAt.getTime(), | ||
}); | ||
|
||
const findMany = async (tx: Prisma.TransactionClient, limit?: number): Promise<TaskEntity[]> => { | ||
const prismaTasks = await tx.task.findMany({ | ||
take: limit, | ||
orderBy: { createdAt: 'desc' }, | ||
}); | ||
|
||
return Promise.all(prismaTasks.map(toModel)); | ||
}; | ||
import assert from 'assert'; | ||
import { taskStorage } from './taskCommand'; | ||
|
||
export const taskQuery = { | ||
findMany, | ||
findById: async (tx: Prisma.TransactionClient, taskId: Maybe<TaskId>): Promise<TaskEntity> => | ||
tx.task.findUniqueOrThrow({ where: { id: taskId } }).then(toModel), | ||
findMany: (): TaskEntity[] => taskStorage, | ||
findById: (taskId: Maybe<TaskId>): TaskEntity => { | ||
const task = taskStorage.find((t) => t.id === taskId); | ||
assert(task); | ||
|
||
return task; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
import type { Maybe, TaskId } from 'api/@types/brandedId'; | ||
import type { TaskCreateVal, TaskEntity, TaskUpdateVal } from 'api/@types/task'; | ||
import { transaction } from 'service/prismaClient'; | ||
import { taskMethod } from '../model/taskMethod'; | ||
import { taskCommand } from '../repository/taskCommand'; | ||
import { taskQuery } from '../repository/taskQuery'; | ||
|
||
export const taskUseCase = { | ||
create: (val: TaskCreateVal): Promise<TaskEntity> => | ||
transaction('RepeatableRead', async (tx) => { | ||
const created = await taskMethod.create(val); | ||
create: (val: TaskCreateVal): TaskEntity => { | ||
const created = taskMethod.create(val); | ||
|
||
await taskCommand.save(tx, created); | ||
taskCommand.save(created); | ||
|
||
return created; | ||
}), | ||
update: (val: TaskUpdateVal): Promise<TaskEntity> => | ||
transaction('RepeatableRead', async (tx) => { | ||
const task = await taskQuery.findById(tx, val.taskId); | ||
const updated = await taskMethod.update(task, val); | ||
return created; | ||
}, | ||
update: (val: TaskUpdateVal): TaskEntity => { | ||
const task = taskQuery.findById(val.taskId); | ||
const updated = taskMethod.update(task, val); | ||
|
||
await taskCommand.save(tx, updated); | ||
taskCommand.save(updated); | ||
|
||
return updated; | ||
}), | ||
delete: (taskId: Maybe<TaskId>): Promise<TaskEntity> => | ||
transaction('RepeatableRead', async (tx) => { | ||
const task = await taskQuery.findById(tx, taskId); | ||
const deleted = taskMethod.delete(task); | ||
return updated; | ||
}, | ||
delete: (taskId: Maybe<TaskId>): TaskEntity => { | ||
const task = taskQuery.findById(taskId); | ||
const deleted = taskMethod.delete(task); | ||
|
||
await taskCommand.delete(tx, deleted); | ||
taskCommand.delete(deleted); | ||
|
||
return task; | ||
}), | ||
return task; | ||
}, | ||
}; |
Oops, something went wrong.