Compare commits
2 Commits
38f769ef67
...
f6b18d3f82
| Author | SHA1 | Date | |
|---|---|---|---|
|
f6b18d3f82
|
|||
|
d660fd12fa
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,3 +12,4 @@ caddy/logs
|
||||
sqlite.db-shm
|
||||
sqlite.db-wal
|
||||
user.json
|
||||
user-p.json
|
||||
|
||||
@@ -10,9 +10,20 @@ import {
|
||||
import { Groups, Opinions, Provinces, Districts } from "./initialData";
|
||||
import { createBucket, createClient } from "./src/minio";
|
||||
import { Config } from "./src/config";
|
||||
import ud from "./user.json";
|
||||
import ud from "./user-p.json";
|
||||
|
||||
const user_data: UserData[] = ud;
|
||||
console.log(ud.length);
|
||||
|
||||
for (const user of user_data) {
|
||||
let thisName = `${user.first_name} ${user.last_name}`;
|
||||
if (
|
||||
user_data.filter((u) => `${u.first_name} ${u.last_name}` == thisName)
|
||||
.length != 1
|
||||
) {
|
||||
console.log(`duplicate name ${user}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
@@ -53,15 +64,15 @@ async function main() {
|
||||
userToSelection: { with: { selection: true } },
|
||||
},
|
||||
});
|
||||
for (const u of allUser) {
|
||||
console.log(
|
||||
u.firstName,
|
||||
u.lastName,
|
||||
u.userToSelection.map(
|
||||
(t) => `${t.selection?.firstName} ${t.selection?.lastName}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
// for (const u of allUser) {
|
||||
// console.log(
|
||||
// u.firstName,
|
||||
// u.lastName,
|
||||
// u.userToSelection.map(
|
||||
// (t) => `${t.selection?.firstName} ${t.selection?.lastName}`,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
console.log("Done");
|
||||
}
|
||||
|
||||
@@ -71,7 +82,9 @@ type UserData = {
|
||||
job_code: number;
|
||||
selection: string[];
|
||||
province: string;
|
||||
province_code: number;
|
||||
district: string;
|
||||
district_code: number;
|
||||
rank: number;
|
||||
};
|
||||
|
||||
@@ -79,14 +92,14 @@ 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.name == newUser.province);
|
||||
const thisDistrict = district.find((p) => p.name == newUser.district);
|
||||
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.district == newUser.district,
|
||||
p.province_code == newUser.province_code,
|
||||
);
|
||||
if (isFound == -1) {
|
||||
isSelectionFound = false;
|
||||
@@ -133,8 +146,8 @@ async function create_relation() {
|
||||
(raw) =>
|
||||
raw.first_name == u.firstName &&
|
||||
raw.last_name == u.lastName &&
|
||||
raw.district == u.zone.name &&
|
||||
raw.province == u.zone.province.name,
|
||||
raw.district_code == u.zone.id &&
|
||||
raw.province_code == u.zone.province.id,
|
||||
);
|
||||
if (thisUsers.length !== 1) {
|
||||
console.log("duplicated users", thisUsers);
|
||||
@@ -144,7 +157,7 @@ async function create_relation() {
|
||||
const selections = allUser.filter(
|
||||
(target) =>
|
||||
rawUser.selection.includes(`${target.firstName} ${target.lastName}`) &&
|
||||
target.zone.id == u.zone.id,
|
||||
target.zone.province.id == u.zone.province.id,
|
||||
);
|
||||
if (selections.length == 0) {
|
||||
console.log("selection not found", selections);
|
||||
|
||||
@@ -177,7 +177,7 @@ async function getAllUser(
|
||||
},
|
||||
},
|
||||
});
|
||||
const topThree = await db.query.user.findMany({
|
||||
const topTen = await db.query.user.findMany({
|
||||
with: {
|
||||
group: true,
|
||||
opinions: {
|
||||
@@ -187,7 +187,7 @@ async function getAllUser(
|
||||
with: { province: true },
|
||||
},
|
||||
},
|
||||
limit: 3,
|
||||
limit: 10,
|
||||
orderBy: user.rank,
|
||||
where: (user, { eq, and }) => {
|
||||
const conditions: SQL[] = [];
|
||||
@@ -247,17 +247,19 @@ async function getAllUser(
|
||||
];
|
||||
} else {
|
||||
resultUser = [
|
||||
...topThree,
|
||||
...users.filter((u) => topThree.filter((v) => v.id == u.id).length == 0),
|
||||
...topTen,
|
||||
...users.filter((u) => topTen.filter((v) => v.id == u.id).length == 0),
|
||||
];
|
||||
}
|
||||
|
||||
return resultUser.map((u) => ({
|
||||
...u,
|
||||
phone: hidePhone(u.phone),
|
||||
verified: true,
|
||||
image: u.image ? `${Config.minioPublicBucketEndpoint}${u.image}` : null,
|
||||
}));
|
||||
return resultUser
|
||||
.map((u) => ({
|
||||
...u,
|
||||
phone: hidePhone(u.phone),
|
||||
verified: true,
|
||||
image: u.image ? `${Config.minioPublicBucketEndpoint}${u.image}` : null,
|
||||
}))
|
||||
.slice(0, limit);
|
||||
}
|
||||
|
||||
async function getUser(userId: number, showPhone: boolean) {
|
||||
|
||||
Reference in New Issue
Block a user