Sead amin
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
const ADMIN_MOBILES = ['09185290775', '09188630559'];
|
||||
|
||||
export class FixAdminUsersSeed1720800000000 implements MigrationInterface {
|
||||
name = 'FixAdminUsersSeed1720800000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
for (const mobile of ADMIN_MOBILES) {
|
||||
await queryRunner.query(
|
||||
`
|
||||
DELETE FROM customers
|
||||
WHERE "userId" IN (
|
||||
SELECT id FROM users WHERE mobile = $1
|
||||
)
|
||||
`,
|
||||
[mobile],
|
||||
);
|
||||
|
||||
const existingUsers: Array<{ id: string }> = await queryRunner.query(
|
||||
`SELECT id FROM users WHERE mobile = $1`,
|
||||
[mobile],
|
||||
);
|
||||
|
||||
if (existingUsers.length > 0) {
|
||||
await queryRunner.query(
|
||||
`UPDATE users SET role = 'admin' WHERE mobile = $1`,
|
||||
[mobile],
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
const firstName = mobile === '09185290775' ? 'hamid' : 'ادمین';
|
||||
const lastName = mobile === '09185290775' ? 'Zarghami' : 'گرو';
|
||||
|
||||
await queryRunner.query(
|
||||
`
|
||||
INSERT INTO users ("firstName", "lastName", mobile, role)
|
||||
VALUES ($1, $2, $3, 'admin')
|
||||
`,
|
||||
[firstName, lastName, mobile],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
for (const mobile of ADMIN_MOBILES) {
|
||||
await queryRunner.query(`DELETE FROM users WHERE mobile = $1`, [mobile]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user