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
import RouteHandler from './route-handler'; | |
export default RouteHandler({ | |
GET(req, res) { | |
// get logic goes in here | |
}, | |
POST(req, res) { | |
// post logic goes in here | |
} | |
}); |
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
import type { NextApiRequest, NextApiResponse } from "next"; | |
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"; | |
type HttpHandler = (request: NextApiRequest, response: NextApiResponse) => void; | |
interface RouteHandlerParams { | |
GET?: HttpHandler; | |
POST?: HttpHandler; | |
PUT?: HttpHandler; | |
DELETE?: HttpHandler; |
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
import { Injectable } from '@nestjs/common'; | |
import { PrismaService } from 'src/prisma.service'; | |
import { EventCreateDTO } from '../dto/event-create.dto'; | |
import { OnEvent, EventEmitter2 } from '@nestjs/event-emitter'; | |
import { EventTriggeredEvent } from '../events/event-triggered.event'; | |
import { HttpService } from '@nestjs/axios'; | |
@Injectable() | |
export class EventService { | |
constructor( |
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
model Event { | |
id Int @id @default(autoincrement()) | |
name String | |
actions Action[] | |
} | |
model Action { | |
id Int @id @default(autoincrement()) | |
name String | |
endpoint String |
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
import type { NextApiRequest, NextApiResponse } from "next"; | |
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"; | |
export const CrudRouteHandler = async <T>( | |
request: NextApiRequest, | |
response: NextApiResponse, | |
service: ICrudService<T> | |
) => { | |
const id = request.query.id as string; |
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
export interface ICrudService<T> { | |
getAll: () => Promise<T[]>; | |
getOne: (id: string) => Promise<T | null>; | |
create: (data: T) => Promise<T>; | |
update: (id: string, data: T) => Promise<T>; | |
delete: (id: string) => Promise<T>; | |
} |
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
interface Todo { | |
description: string; | |
complete: boolean; | |
} | |
const useTodoListViewModel = () => { | |
const [todos, setTodos] = useState<Todo[]>([]); | |
const createTodo = (description: string) => { | |
const newTodo: Todo = { |
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
const Todos = () => { | |
const listVm = useTodoListViewModel(); | |
const addTodoVm = useAddTodoVm(listVm.createTodo); | |
return ( | |
<> | |
<TodoList todos={listVm.todos} /> | |
<AddTodo viewModel={addTodoVm} /> | |
</> | |
); |
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
const useAddTodoVm = (onAdd: (description: string) => void) => { | |
const [inputText, setInputText] = useState(""); | |
const addTodo = () => { | |
onAdd(inputText); | |
setInputText(""); | |
}; | |
return { | |
inputText, |
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
const useTodoListViewModel = () => { | |
const [todos, setTodos] = useState<Todo[]>([]); | |
const createTodo = (description: string) => { | |
const newTodo: Todo = { | |
description, | |
complete: false, | |
}; | |
setTodos((current) => [...current, newTodo]); |
NewerOlder