randomize result
All checks were successful
backend-action / build-image (push) Successful in 11m53s

This commit is contained in:
2024-06-24 15:16:47 +07:00
parent f6b18d3f82
commit cba647ca27
3 changed files with 18 additions and 27 deletions

View File

@@ -10,7 +10,7 @@ import {
import { Groups, Opinions, Provinces, Districts } from "./initialData";
import { createBucket, createClient } from "./src/minio";
import { Config } from "./src/config";
import ud from "./user-p.json";
import ud from "./user-c.json";
const user_data: UserData[] = ud;
console.log(ud.length);
@@ -82,9 +82,6 @@ type UserData = {
job_code: number;
selection: string[];
province: string;
province_code: number;
district: string;
district_code: number;
rank: number;
};
@@ -92,31 +89,17 @@ async function create_user() {
const provinces = await db.query.province.findMany({});
const district = await db.query.zone.findMany({});
for (const newUser of user_data) {
const thisProvince = provinces.find((p) => p.id == newUser.province_code);
const thisDistrict = district.find((p) => p.id == newUser.district_code);
let isSelectionFound = true;
for (const selection of newUser.selection) {
const isFound = user_data.findIndex(
(p) =>
`${p.first_name} ${p.last_name}` == selection &&
p.province_code == newUser.province_code,
(p) => `${p.first_name} ${p.last_name}` == selection,
);
if (isFound == -1) {
isSelectionFound = false;
}
}
if (
thisProvince === undefined ||
thisDistrict === undefined ||
!isSelectionFound
) {
console.log(
newUser.province,
newUser.district,
thisDistrict,
thisProvince,
isSelectionFound,
);
if (!isSelectionFound) {
console.log(newUser.province, newUser, isSelectionFound);
} else {
await db.insert(user).values({
group: newUser.job_code,
@@ -128,7 +111,7 @@ async function create_user() {
age: 0,
job: "",
education: "",
zone: thisDistrict.id,
zone: 1001,
rank: newUser.rank,
});
}
@@ -143,11 +126,7 @@ async function create_relation() {
});
for (const u of allUser) {
let thisUsers = user_data.filter(
(raw) =>
raw.first_name == u.firstName &&
raw.last_name == u.lastName &&
raw.district_code == u.zone.id &&
raw.province_code == u.zone.province.id,
(raw) => raw.first_name == u.firstName && raw.last_name == u.lastName,
);
if (thisUsers.length !== 1) {
console.log("duplicated users", thisUsers);