async create(request, responce){ const { title, description, value } = request.body; const ong_id = request.headers.authorization; const [ id ] = await connection('incidents').insert({ title, description, value, ong_id }); responce.json({ id }) }
async function checkId(id) { // Vai retornar verdadeiro se o id existir const ongWithIdExist = await connection('ongs') .select('*') .where({ 'id': id }) .first(); while (ongWithIdExist) { id = genareteId(); } return id }
async search(request, response) { const pokemons = await connection('pokemons') .select('*'); return response.json(pokemons); }
async delete(request, response) { const { id } = request.params; try { const group = await connection('group') .where({ id }) .delete(); if (group) return response.status(204).send(); else return response.status(404).send(); } catch (error) { return response.status(500).send(error); } }
async index(request, response) { const pokemon_id = request.headers.pokemon_id; const pokemons = await connection('attributes') .join('pokemons', 'pokemons.id', '=', 'attributes.pokemon_id') .limit(1) .where('attributes.pokemon_id', pokemon_id) .select(['pokemons.*', 'attributes.total', 'attributes.hp', 'attributes.attack', 'attributes.defense', 'attributes.sp_atk', 'attributes.sp_def', 'attributes.speed']); return response.json(pokemons); }
async list(request, response) { ong_id = request.headers.authorization if (!ong_id) { return response.json('Unauthorized', 401) } const incidents = await connection('incident') .select('*') .where({ ong_id }) return response.json(incidents) }
async index(request, response) { const { id } = request.params; try { const group = await connection('groups') .where({ id }) .first('*'); if (group) return response.json(group); else return response.status(404).send(); } catch (error) { return response.status(500).send(error); } }
//getID para puxar por ong - seja doador ou ong async getByID (req,res){ const id_ongs = req.params.id_ongs const item = await connection('incid') .select() .where('id_ongs', id_ongs) return res.json(item) }
async create(request, response) { const {name, email, whatsapp, city, uf} = request.body const id = generateUniqueId() await connection('ngos').insert({ id, name, email, whatsapp, city, uf, }) return response.json({ id }) }
async create (request, responce) { const { id } = request.body; const ong = await connection('ongs') .where('id', id) .select('name') .first(); if (!ong) { return responce.status(400).json({ error: 'No ONG found with this ID' }); } return responce.json(ong); }
async one(request, response) { const { id } = request.params const ong = await connection('ong') .select('*') .where({ id }) .first() return response.json(ong) }
async incidentsByOngId(request, response){ const ongId = request.headers.authorization; const result = await connection('incidents').where('ongId', ongId).select('*'); response.json(result); }
async index(request, response) { const ong_id = request.headers.authorization; const incidents = await connection('incidents') .where('ong_id', ong_id) .select('*'); return response.json(incidents); }
async index (request, responce) { const ong_id = request.headers.authorization; const incidents = await connection('incidents') .where('ong_id', ong_id) .select('*'); return responce.json(incidents); }
async list(request, response) { const ongs = await connection('ong') .select('*') return response.json(ongs) }