fix estelam
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user