-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Kaduh15/dev
Dev
- Loading branch information
Showing
40 changed files
with
719 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"prisma.fileWatcher": true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BaseEntity } from './base.entity' | ||
|
||
export type Status = 'WAITING' | 'ABSENT' | 'DONE' | ||
|
||
export default class Open extends BaseEntity { | ||
isOpen: boolean | ||
|
||
constructor({ id, createdAt, updatedAt, isOpen }: Open) { | ||
super({ | ||
id, | ||
createdAt, | ||
updatedAt, | ||
}) | ||
|
||
this.isOpen = isOpen | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { BaseEntity } from './base.entity' | ||
|
||
export type Status = 'WAITING' | 'ABSENT' | 'DONE' | ||
|
||
export default class Queue extends BaseEntity { | ||
name: string | ||
phoneNumber: string | ||
status: Status | ||
|
||
constructor({ id, name, createdAt, updatedAt, phoneNumber, status }: Queue) { | ||
super({ | ||
id, | ||
createdAt, | ||
updatedAt, | ||
}) | ||
this.name = name | ||
this.phoneNumber = phoneNumber | ||
this.status = status | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/backend/src/prisma/migrations/20230727235837_create_queue_table/migration.sql
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- CreateTable | ||
CREATE TABLE "queue" ( | ||
"id" SERIAL NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"phone" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "queue_pkey" PRIMARY KEY ("id") | ||
); |
10 changes: 10 additions & 0 deletions
10
...igrations/20230728003253_rename_colunm_phone_for_phone_numbr_in_queue_table/migration.sql
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `phone` on the `queue` table. All the data in the column will be lost. | ||
- Added the required column `phoneNumber` to the `queue` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "queue" DROP COLUMN "phone", | ||
ADD COLUMN "phoneNumber" TEXT NOT NULL; |
5 changes: 5 additions & 0 deletions
5
...ckend/src/prisma/migrations/20230728111357_add_status_column_in_queue_table/migration.sql
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- CreateEnum | ||
CREATE TYPE "Status" AS ENUM ('WAITING', 'ABSENT', 'DONE'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "queue" ADD COLUMN "status" "Status" NOT NULL DEFAULT 'WAITING'; |
9 changes: 9 additions & 0 deletions
9
...migrations/20230728194554_add_update_at_and_created_at_column_in_open_table/migration.sql
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `updatedAt` to the `Open` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Open" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; |
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
68 changes: 68 additions & 0 deletions
68
app/backend/src/repositories/open-repository/open-in-memory.repository.ts
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Open from '@/entities/open.entity' | ||
import { NotFoundError } from '@/utils/http-errors' | ||
|
||
import { OpenRepository } from './open.repository' | ||
|
||
export class OpenRepositoryInMemory implements OpenRepository { | ||
opens: Open[] = [] | ||
index = 0 | ||
|
||
create({ | ||
isOpen = false, | ||
}: Omit<Open, 'id' | 'createdAt' | 'updatedAt'>): Promise<Open> { | ||
const date = new Date() | ||
|
||
const open = new Open({ | ||
id: this.index + 1, | ||
isOpen, | ||
createdAt: date, | ||
updatedAt: date, | ||
}) | ||
|
||
this.opens.push(open) | ||
this.index++ | ||
|
||
return Promise.resolve(open) | ||
} | ||
|
||
getAll(): Promise<Open[]> { | ||
return Promise.resolve(this.opens) | ||
} | ||
|
||
getById(id: number): Promise<Open | undefined> { | ||
const open = this.opens.find((open) => open.id === id) | ||
|
||
return Promise.resolve(open) | ||
} | ||
|
||
update(id: number, data: Partial<Open>): Promise<Open> { | ||
const open = this.opens.find((open) => open.id === id) | ||
|
||
if (!open) { | ||
return Promise.reject(NotFoundError) | ||
} | ||
open.isOpen = data.isOpen ?? open.isOpen | ||
|
||
open.updatedAt = new Date() | ||
|
||
return Promise.resolve(new Open(open)) | ||
} | ||
|
||
delete(id: number): Promise<void> { | ||
const index = this.opens.findIndex((open) => open.id === id) | ||
|
||
if (!index) { | ||
return Promise.reject(NotFoundError) | ||
} | ||
|
||
this.opens.splice(index, 1) | ||
|
||
return Promise.resolve() | ||
} | ||
|
||
deleteAll(): Promise<void> { | ||
this.opens = [] | ||
|
||
return Promise.resolve() | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
app/backend/src/repositories/open-repository/open-prisma.repository.ts
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Open from '@/entities/open.entity' | ||
import prisma from '@/prisma/prisma-client' | ||
|
||
import { OpenRepository } from './open.repository' | ||
|
||
export class OpenPrismaRepository implements OpenRepository { | ||
async create( | ||
data: Omit<Open, 'id' | 'createdAt' | 'updatedAt'>, | ||
): Promise<Open> { | ||
const open = await prisma.open.create({ | ||
data, | ||
}) | ||
|
||
return new Open(open) | ||
} | ||
|
||
getAll(): Promise<Open[]> { | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
async getById(id: number): Promise<Open | undefined> { | ||
const open = await prisma.open.findUnique({ | ||
where: { id }, | ||
}) | ||
|
||
if (!open) return undefined | ||
|
||
return new Open(open) | ||
} | ||
|
||
async update(id: number, data: Partial<Open>): Promise<Open> { | ||
const openUpdated = await prisma.open.update({ | ||
where: { id }, | ||
data, | ||
}) | ||
|
||
return new Open(openUpdated) | ||
} | ||
|
||
delete(_id: number): Promise<void> { | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
async deleteAll(): Promise<void> { | ||
await prisma.open.deleteMany() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/backend/src/repositories/open-repository/open.repository.ts
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Open from '@/entities/open.entity' | ||
|
||
import { BaseRepository } from '../base.repository' | ||
|
||
export type OpenRepository = BaseRepository<Open> |
63 changes: 63 additions & 0 deletions
63
app/backend/src/repositories/queue-repository/queue-in-memory.repository.ts
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Queue from '@/entities/queue.entity' | ||
|
||
import { QueueRepository } from './queue.repository' | ||
|
||
export class QueueRepositoryInMemory implements QueueRepository { | ||
private queues: Queue[] = [] | ||
private index = 1 | ||
|
||
getToday(): Promise<Queue[]> { | ||
const queueToday = this.queues.filter((queue) => { | ||
const today = new Date() | ||
const queueDate = new Date(queue.createdAt) | ||
|
||
return ( | ||
queueDate.getDate() === today.getDate() && | ||
queueDate.getMonth() === today.getMonth() && | ||
queueDate.getFullYear() === today.getFullYear() | ||
) | ||
}) | ||
|
||
return Promise.resolve(queueToday) | ||
} | ||
|
||
create(data: Omit<Queue, 'id'>): Promise<Queue> { | ||
const nowDate = new Date() | ||
|
||
const newQueue = new Queue({ | ||
...data, | ||
id: this.index, | ||
createdAt: nowDate, | ||
updatedAt: nowDate, | ||
status: 'WAITING', | ||
}) | ||
|
||
this.queues.push(newQueue) | ||
|
||
this.index++ | ||
|
||
return Promise.resolve(newQueue) | ||
} | ||
|
||
getAll(): Promise<Queue[]> { | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
getById(_id: number): Promise<Queue | undefined> { | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
update(_id: number, _data: Partial<Queue>): Promise<Queue> { | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
delete(_id: number): Promise<void> { | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
deleteAll(): Promise<void> { | ||
this.queues = [] | ||
|
||
return Promise.resolve() | ||
} | ||
} |
Oops, something went wrong.