mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
properly typecast and do thing right
This commit is contained in:
parent
8afd66088d
commit
97b169da2e
@ -3,6 +3,7 @@
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { OkPacket } from 'mysql'
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
const missingUserIds = await queryFn(`
|
||||
@ -10,8 +11,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
WHERE NOT EXISTS (SELECT id FROM users WHERE id = user_id) GROUP BY user_id;`)
|
||||
|
||||
for (let i = 0; i < missingUserIds.length; i++) {
|
||||
let gradidoId = null
|
||||
let countIds = null
|
||||
let gradidoId = ''
|
||||
let countIds: any[] = []
|
||||
do {
|
||||
gradidoId = uuidv4()
|
||||
countIds = await queryFn(
|
||||
@ -19,19 +20,17 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
)
|
||||
} while (countIds[0] > 0)
|
||||
|
||||
const userContact = await queryFn(`
|
||||
const userContact = (await queryFn(`
|
||||
INSERT INTO user_contacts
|
||||
(type, user_id, email, email_checked, created_at, deleted_at)
|
||||
VALUES
|
||||
('EMAIL', ${missingUserIds[i].user_id}, 'deleted.user${missingUserIds[i].user_id}@gradido.net', 0, NOW(), NOW());`)
|
||||
|
||||
const emaiId = Object.values(userContact)[Object.keys(userContact).indexOf('insertId')]
|
||||
('EMAIL', ${missingUserIds[i].user_id}, 'deleted.user${missingUserIds[i].user_id}@gradido.net', 0, NOW(), NOW());`)) as unknown as OkPacket
|
||||
|
||||
await queryFn(`
|
||||
INSERT INTO users
|
||||
(id, gradido_id, email_id, first_name, last_name, deleted_at, password_encryption_type, created_at, language)
|
||||
VALUES
|
||||
(${missingUserIds[i].user_id}, '${gradidoId}', ${emaiId}, 'DELETED', 'USER', NOW(), 0, NOW(), 'de');`)
|
||||
(${missingUserIds[i].user_id}, '${gradidoId}', ${userContact.insertId}, 'DELETED', 'USER', NOW(), 0, NOW(), 'de');`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user