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
# BEFORE | |
const response = await groqClient.chat.completions.create({ | |
messages: [ | |
// Your messages here | |
], | |
model: "your-model", | |
response_format: { | |
type: "json_object" | |
} | |
}); |
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 moment from "moment"; | |
import { CacheProperties } from "../../@types/Cache"; | |
export default class CacheService { | |
public set(key: string, value: string, validityInMinutes: number = 0): boolean { | |
try { | |
const properties: CacheProperties = { | |
key, | |
value, | |
createdAt: moment().format(), |
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 { Request, Response } from "express"; | |
import { validationResult } from "express-validator"; | |
import { UserService } from "../services/UserService"; | |
export class UserController { | |
service: UserService; | |
constructor(){ | |
this.service = new UserService(); | |
} |
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 { pool } from "database"; | |
export class UserService{ | |
public create(data: ICreateUserData){ | |
return pool.query(`INSERT...`); | |
} | |
} |
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 { Application } from "express"; | |
import { UserController } from "../controllers/UserController"; | |
import { validatePost } from "../middlewares/validators/userValidator"; | |
export default function userRoutes(app: Application) { | |
const controller = new UserController(); | |
app.post( | |
"/user", | |
validatePost(), |
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 { Request, Response } from "express"; | |
import { pool } from "database"; | |
import { validationResult } from "express-validator"; | |
export class UserController { | |
public async create(req: Request, res: Response) { | |
try { | |
const errors = validationResult(req); | |
if (!errors.isEmpty()) { |
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 { body, ValidationChain } from "express-validator"; | |
export function validatePost(): ValidationChain[] { | |
return [ | |
body("name", "check the field 'name' and try again.") | |
.isString() | |
.isLength({ min: 3, max: 35 }), | |
body("email", "check the field 'email' and try again").isEmail(), |
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 { Application } from "express"; | |
import { UserController } from "../controllers/UserController"; | |
export default function userRoutes(app: Application) { | |
const controller = new UserController(); | |
app.post( | |
"/user", | |
controller.create.bind(controller) | |
); |
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 { Request, Response } from "express"; | |
import { pool } from "database"; | |
export class UserController { | |
public async create(req: Request, res: Response) { | |
const { name, password, email } = req.body; | |
if (!name) { | |
return res.status(400).json({ message: "Field name cannot be empty" }); | |
} |
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
function solucao(esquerda, direita){ | |
if (esquerda > direita){ | |
console.log("esquerda ganhando"); | |
} else if (esquerda < direita){ | |
console.log("direita ganhando"); | |
} else if (esquerda + direita === 0){ | |
console.log("nenhum voto"); |
NewerOlder