This file contains hidden or 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
| dependencies: | |
| flutter: | |
| sdk: flutter | |
| get: ^2.12.1 | |
| meta: ^1.1.8 | |
| http: ^0.12.1 |
This file contains hidden or 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 const deleteUser = async (req: Request, res: Response) => { | |
| await Client.deleteById(req.params.id) | |
| res.status(200).send({ clients: Client.all() }) | |
| } |
This file contains hidden or 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 const updateUser = async (req: Request, res: Response) => { | |
| const body = await req.body() | |
| if (Client.select('id', '===', req.params.id)) { | |
| await Client.where('id', req.params.id).update({ name: body.value.name, email: body.value.email }) | |
| res.status(200).send({ clients: Client.all() }) | |
| }else{ | |
| res.status(404).send({ message: "usuário não encontrado" }) | |
| } | |
| } |
This file contains hidden or 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 const getUser = async (req: Request, res: Response) => { | |
| res.status(200).send({ client: await Client.where('id', req.params.id).first() }) | |
| } |
This file contains hidden or 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 const addUser = async (req: Request, res: Response) => { | |
| const body = await req.body() | |
| const client: Client = body.value | |
| //console.log(client) | |
| const { name, email, password } = body.value | |
| //await Client.create( body.value ) | |
| await Client.create({ name: name, email: email, password: password }) | |
| res.status(200).send({ client: client }) | |
| } |
This file contains hidden or 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 const getUsers = async (req: Request, res: Response) => { | |
| res.status(200).send({ clients: await Client.all() }) | |
| } |
This file contains hidden or 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 Client from "../models/client.ts" | |
| import { Request, Response } from "https://deno.land/x/attain/mod.ts"; |
This file contains hidden or 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 { Router } from "https://deno.land/x/attain/mod.ts"; | |
| import { getUsers, getUser, updateUser, addUser, deleteUser } from "../controllers/client_controller.ts" | |
| const clientsRouter = new Router() | |
| clientsRouter.get("/", getUsers ) | |
| clientsRouter.get("/:id", getUser) | |
| clientsRouter.put("/:id", updateUser); |
This file contains hidden or 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 { DATA_TYPES, Model } from 'https://deno.land/x/denodb/mod.ts' | |
| export default class Client extends Model { | |
| static table = "clients" | |
| static timestamps = true | |
| static fields = { | |
| id : { | |
| primaryKey : true, | |
| autoIncrement: true |
This file contains hidden or 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 { Database } from 'https://deno.land/x/denodb/mod.ts'; | |
| import Client from "../models/client.ts"; | |
| const db = new Database( | |
| "mysql",{ | |
| database: "NOME-DA-BASE-DE-DADOS", | |
| host: "localhost", | |
| username: "root", | |
| password: "senha", | |