mirror of https://github.com/xfarrow/blink
update
This commit is contained in:
parent
a29a8877d5
commit
7378c85d50
|
@ -14,15 +14,22 @@
|
|||
const knex = require('../utils/knex_config');
|
||||
|
||||
async function insert(personId, infoContent, infoType) {
|
||||
return await knex('PersonContactInfo')
|
||||
const contactInfo = await knex('PersonContactInfo')
|
||||
.insert({
|
||||
person_id: personId,
|
||||
info: infoContent,
|
||||
info_type: infoType
|
||||
})
|
||||
.returning("*");
|
||||
return contactInfo[0];
|
||||
}
|
||||
|
||||
async function getInfoByPerson(personId) {
|
||||
return await knex('PersonContactInfo')
|
||||
.where('person_id', personId);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
insert
|
||||
insert,
|
||||
getInfoByPerson
|
||||
}
|
|
@ -13,13 +13,13 @@
|
|||
|
||||
const express = require('express');
|
||||
const jwtUtils = require('../utils/jwt_utils');
|
||||
const PersonContactInfo = require('../models/person_contact_info');
|
||||
const PersonContactInfo = require('../models/person_contact_info_model');
|
||||
|
||||
async function insert(req, res) {
|
||||
try {
|
||||
const contactInfo = PersonContactInfo.insert(req.jwt.person_id, req.body.content, req.body.info_type);
|
||||
const contactInfo = await PersonContactInfo.insert(req.jwt.person_id, req.body.content, req.body.info_type);
|
||||
res.set('Location', `/api/persons/${req.jwt.person_id}/contactinfos/${contactInfo.id}`);
|
||||
return res.status(201).json(application);
|
||||
return res.status(201).json(contactInfo);
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${insert.name}: ${error}`);
|
||||
res.status(500).json({
|
||||
|
@ -28,8 +28,25 @@ async function insert(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
async function findByPerson(req, res) {
|
||||
try {
|
||||
const infos = await PersonContactInfo.getInfoByPerson(req.params.personId);
|
||||
return res.status(200).json(infos);
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${insert.name}: ${error}`);
|
||||
res.status(500).json({
|
||||
error: 'Internal server error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(req, res){
|
||||
|
||||
}
|
||||
|
||||
const routes = express.Router();
|
||||
routes.post('/myself/contactinfos', jwtUtils.extractToken, insert);
|
||||
routes.get('/:personId/contactinfos', jwtUtils.extractToken, findByPerson)
|
||||
module.exports = {
|
||||
routes
|
||||
};
|
Loading…
Reference in New Issue