Inicio de POST

parent f614ce66
...@@ -14,7 +14,7 @@ export class Jogo { ...@@ -14,7 +14,7 @@ export class Jogo {
} }
public writeinfo(): string { public writeinfo(): string {
return "nome: " + this.name + " preço: " + this.price + "\n desenvolvedora: " + this.developer + "\n produtora: " + this.producer + "\n lançamento: " + this.release+ "."; return "nome: " + this.name + " preço: " + this.price + " desenvolvedora: " + this.developer + " produtora: " + this.producer + " lançamento: " + this.release+ ".";
} }
public getname(): string { public getname(): string {
return this.name; return this.name;
......
...@@ -25,7 +25,13 @@ const app = express(); ...@@ -25,7 +25,13 @@ const app = express();
app.use("/", bodyParser.json()); app.use("/", bodyParser.json());
app.use("/", dbhMW()); app.use("/", dbhMW());
app.get("/", (req: Request, res: express.Response) => { app.post("/inicio", (req: Request, res: express.Response) => {
const jogador: Jogador = new Jogador(req.body.nome, [], [], 0);
req.db.createplayer(jogador);
console.log(req.db.readplayer(0).writeinfo());
});
app.post("/", (req: Request, res: express.Response) => {
const jogo1: Jogo = new Jogo("Portal 2", "Valve", "Valve", new Date("2012-01-01"), 25); const jogo1: Jogo = new Jogo("Portal 2", "Valve", "Valve", new Date("2012-01-01"), 25);
const jogo2: Jogo = new Jogo("The Witcher 3", "CD Projekt RED", "CD Projekt RED", new Date("2016-01-01"), 10); const jogo2: Jogo = new Jogo("The Witcher 3", "CD Projekt RED", "CD Projekt RED", new Date("2016-01-01"), 10);
...@@ -81,7 +87,7 @@ app.get("/comprar/amigo", (req: Request, res: express.Response) => { ...@@ -81,7 +87,7 @@ app.get("/comprar/amigo", (req: Request, res: express.Response) => {
if (req.db.readplayer(0).buy(req.db.readgame(0), req.db.readplayer(1)) === 1) { if (req.db.readplayer(0).buy(req.db.readgame(0), req.db.readplayer(1)) === 1) {
const compra = new Compra(req.db.readplayer(0), req.db.readgame(0), new Date("2019-01-01"), req.db.readplayer(1)); const compra = new Compra(req.db.readplayer(0), req.db.readgame(0), new Date("2019-01-01"), req.db.readplayer(1));
req.db.readplayer(0).newmoney(req.db.readgame(0).getprice()); req.db.readplayer(0).newmoney(req.db.readgame(0).getprice());
req.db.readplayer(0).addgame(req.db.readgame(1)); req.db.readplayer(1).addgame(req.db.readgame(0));
req.db.createbuy(compra); req.db.createbuy(compra);
res.json(req.db.readbuy(0).writeinfo() + req.db.readplayer(0).balance()); res.json(req.db.readbuy(0).writeinfo() + req.db.readplayer(0).balance());
} else if (req.db.readplayer(0).buy(req.db.readgame(0), req.db.readplayer(1)) === 3) { } else if (req.db.readplayer(0).buy(req.db.readgame(0), req.db.readplayer(1)) === 3) {
...@@ -97,23 +103,22 @@ app.get("/jogos-em-comum", (req: Request, res: express.Response) => { ...@@ -97,23 +103,22 @@ app.get("/jogos-em-comum", (req: Request, res: express.Response) => {
})); }));
}); });
app.get("/adicionar-amigo", (req: Request, res: express.Response) => { app.get("/adicionar/amigo", (req: Request, res: express.Response) => {
res.json(req.db.readplayer(0).addfriend(req.db.readplayer(1))); res.json(req.db.readplayer(0).addfriend(req.db.readplayer(1)));
}); });
app.get("/adicionar-saldo", (req: Request, res: express.Response) => { app.get("/adicionar/saldo", (req: Request, res: express.Response) => {
const saldo = 200; const saldo = 200;
req.db.readplayer(0).addcredit(saldo); req.db.readplayer(0).addcredit(saldo);
console.log(req.db.readplayer(0).getmoney()); console.log(req.db.readplayer(0).getmoney());
res.json("O jogador " + req.db.readplayer(0).getname() + " adicionou " + saldo + "R$"); res.json("O jogador " + req.db.readplayer(0).getname() + " adicionou " + saldo + "R$");
}); });
app.get("/testando/:batata", (req: Request, res: express.Response) => { app.post("/adicionar-jogos", (req: Request, res: express.Response) => {
res.json({hello: req.params.batata}); const game: Jogo = new Jogo(req.body.nome, req.body.dev, req.body.producer, new Date(req.body.release), req.body.price);
}); req.db.creategame(game);
console.log(req.db.readgame(0).writeinfo());
app.post("/testando/:batata", (req: Request, res: express.Response) => { res.json(game.writeinfo());
res.json(req.body);
}); });
app.listen(3000); app.listen(3000);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment