import { Log } from 'lib/Log'; import { DB } from 'lib/DB'; import { ServerError, Status } from 'nice-grpc'; import type { Buyer } from '@nextgenleads/dnc'; const log = Log.child({ module: 'grpc', service: 'Buyer', method: 'addDisqualified', }); export async function addDisqualified(request: Buyer.AddDisqualifiedRequest): Promise { if (!request.company_id || !request.phone_number) { throw new ServerError(Status.INVALID_ARGUMENT, 'Missing required argument'); } try { const dnc = await DB.DNC.scope({ method: ['buyer', request.company_id] }).findOne({ where: { phone_number: request.phone_number, }, }); if (dnc) { await DB.Disqualification.create({ DNCId: dnc.id, }); } else { log.warn('Unable to find DNC to disqualify'); } } catch (err) { log.error('Failed to disqualify DNC', err); } return {}; }