From 9faaef7ce25da16ae35a09d7cca2e5139ae5dd9d Mon Sep 17 00:00:00 2001 From: mobinesaghi Date: Tue, 21 Oct 2025 19:27:28 +0330 Subject: [PATCH] fix estelam --- src/controllers/user.controller.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/controllers/user.controller.ts b/src/controllers/user.controller.ts index 72b008f..e89657f 100644 --- a/src/controllers/user.controller.ts +++ b/src/controllers/user.controller.ts @@ -5,6 +5,7 @@ import { Person } from '../models/Person.model.js'; import { Log } from '../models/Log.model.js'; import { generateTokens, refreshTokens } from '../services/jibit.service.js'; import { generateToken } from '../utils/token.js'; +import { Op } from 'sequelize'; export const checkUser = async (c: Context) => { try { @@ -78,7 +79,6 @@ export const checkUser = async (c: Context) => { const matched = !!(response as any).matched; if (matched) { - // Keep only one record per number: upsert matched record, delete others const existingByNumber = await Person.findOne({ where: { number } }); let keep: any; if (existingByNumber) { @@ -90,12 +90,10 @@ export const checkUser = async (c: Context) => { } else { keep = await Person.create({ national, number, matched: true, userId: (subjectUser as any).id }); } - // delete any other stray records for this number (if any existed historically) - await Person.destroy({ where: { number, id: { ['ne' as any]: (keep as any).id } } as any }); + await Person.destroy({ where: { number, id: { [Op.ne]: (keep as any).id } } }); return c.json({ matched: true }); } - // unmatched: avoid unique violations; reuse existing if present, else create unmatched const existingByNumber = await Person.findOne({ where: { number } }); if (existingByNumber) { return c.json({ matched: !!existingByNumber.matched });