mirror of
				https://github.com/xfarrow/blink
				synced 2025-06-27 09:03:02 +02:00 
			
		
		
		
	add delete method in contactinfo
This commit is contained in:
		@@ -29,7 +29,15 @@ async function getInfoByPerson(personId) {
 | 
			
		||||
        .where('person_id', personId);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function remove(contactInfoId, personId) {
 | 
			
		||||
    return (await knex('PersonContactInfo')
 | 
			
		||||
        .where('id', contactInfoId)
 | 
			
		||||
        .where('person_id', personId)
 | 
			
		||||
        .del() === 1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    insert,
 | 
			
		||||
    remove,
 | 
			
		||||
    getInfoByPerson
 | 
			
		||||
}
 | 
			
		||||
@@ -40,13 +40,26 @@ async function findByPerson(req, res) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function remove(req, res){
 | 
			
		||||
    
 | 
			
		||||
async function remove(req, res) {
 | 
			
		||||
    try {
 | 
			
		||||
        const success = await PersonContactInfo.remove(req.params.contactInfoId, req.jwt.person_id);
 | 
			
		||||
        if (success) {
 | 
			
		||||
            return res.status(200).send();
 | 
			
		||||
        } else {
 | 
			
		||||
            return res.status(400).send();
 | 
			
		||||
        }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
        console.error(`Error in function ${insert.name}: ${error}`);
 | 
			
		||||
        res.status(500).json({
 | 
			
		||||
            error: 'Internal server error'
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const routes = express.Router();
 | 
			
		||||
routes.post('/myself/contactinfos', jwtUtils.extractToken, insert);
 | 
			
		||||
routes.get('/:personId/contactinfos', jwtUtils.extractToken, findByPerson)
 | 
			
		||||
routes.delete('/contactinfos/:contactInfoId', jwtUtils.extractToken, remove)
 | 
			
		||||
module.exports = {
 | 
			
		||||
    routes
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user