Compare commits
6 Commits
3d6de91dc8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
cba647ca27
|
|||
|
f6b18d3f82
|
|||
|
d660fd12fa
|
|||
|
38f769ef67
|
|||
|
b152175499
|
|||
|
e0655a56d7
|
@@ -1,33 +0,0 @@
|
||||
name: backend-admin-action
|
||||
run-name: ${{ gitea.actor }} is building docker image 🚀
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build-image:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
registry: gitea.cognizata.com
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: next.Dockerfile
|
||||
push: true
|
||||
platforms: linux/amd64
|
||||
tags: gitea.cognizata.com/atapy/sorvor-admin:latest
|
||||
- name: update server
|
||||
uses: https://github.com/appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: 46.102.174.196
|
||||
username: root
|
||||
key: ${{ secrets.SORVOR_KEY }}
|
||||
port: 22
|
||||
script: "docker compose pull && docker compose up -d"
|
||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -12,3 +12,5 @@ caddy/logs
|
||||
sqlite.db-shm
|
||||
sqlite.db-wal
|
||||
user.json
|
||||
user-p.json
|
||||
user-c.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-c.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,6 @@ type UserData = {
|
||||
job_code: number;
|
||||
selection: string[];
|
||||
province: string;
|
||||
district: string;
|
||||
rank: number;
|
||||
};
|
||||
|
||||
@@ -79,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.name == newUser.province);
|
||||
const thisDistrict = district.find((p) => p.name == newUser.district);
|
||||
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) => `${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,
|
||||
@@ -115,7 +111,7 @@ async function create_user() {
|
||||
age: 0,
|
||||
job: "",
|
||||
education: "",
|
||||
zone: thisDistrict.id,
|
||||
zone: 1001,
|
||||
rank: newUser.rank,
|
||||
});
|
||||
}
|
||||
@@ -130,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 == u.zone.name &&
|
||||
raw.province == u.zone.province.name,
|
||||
(raw) => raw.first_name == u.firstName && raw.last_name == u.lastName,
|
||||
);
|
||||
if (thisUsers.length !== 1) {
|
||||
console.log("duplicated users", thisUsers);
|
||||
@@ -144,7 +136,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);
|
||||
|
||||
1
drizzle/0001_last_hiroim.sql
Normal file
1
drizzle/0001_last_hiroim.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE users ADD `rank` integer DEFAULT 9999;
|
||||
551
drizzle/meta/0001_snapshot.json
Normal file
551
drizzle/meta/0001_snapshot.json
Normal file
@@ -0,0 +1,551 @@
|
||||
{
|
||||
"version": "5",
|
||||
"dialect": "sqlite",
|
||||
"id": "d7a1e002-36b8-4c25-b935-c826f0a2aaab",
|
||||
"prevId": "b46f7266-bc92-4a23-b12d-d162624db70a",
|
||||
"tables": {
|
||||
"groups": {
|
||||
"name": "groups",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"groups_name_unique": {
|
||||
"name": "groups_name_unique",
|
||||
"columns": [
|
||||
"name"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"image_to_user": {
|
||||
"name": "image_to_user",
|
||||
"columns": {
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"image_name": {
|
||||
"name": "image_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_on": {
|
||||
"name": "created_on",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"image_to_user_user_id_users_id_fk": {
|
||||
"name": "image_to_user_user_id_users_id_fk",
|
||||
"tableFrom": "image_to_user",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"opinions": {
|
||||
"name": "opinions",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'5Choice'"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"opinions_name_unique": {
|
||||
"name": "opinions_name_unique",
|
||||
"columns": [
|
||||
"name"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"provinces": {
|
||||
"name": "provinces",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"provinces_name_unique": {
|
||||
"name": "provinces_name_unique",
|
||||
"columns": [
|
||||
"name"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"users": {
|
||||
"name": "users",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"firstName": {
|
||||
"name": "firstName",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"lastName": {
|
||||
"name": "lastName",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"registerno": {
|
||||
"name": "registerno",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"cid": {
|
||||
"name": "cid",
|
||||
"type": "text(13)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"age": {
|
||||
"name": "age",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"phone": {
|
||||
"name": "phone",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"public_phone": {
|
||||
"name": "public_phone",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"facebook": {
|
||||
"name": "facebook",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"twitter": {
|
||||
"name": "twitter",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"tiktok": {
|
||||
"name": "tiktok",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"other_social": {
|
||||
"name": "other_social",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"image": {
|
||||
"name": "image",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"job": {
|
||||
"name": "job",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"education": {
|
||||
"name": "education",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"vision": {
|
||||
"name": "vision",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"reason": {
|
||||
"name": "reason",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"group_id": {
|
||||
"name": "group_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"zone_id": {
|
||||
"name": "zone_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"verified": {
|
||||
"name": "verified",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"rank": {
|
||||
"name": "rank",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": 9999
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"phone_idx": {
|
||||
"name": "phone_idx",
|
||||
"columns": [
|
||||
"phone"
|
||||
],
|
||||
"isUnique": false
|
||||
},
|
||||
"image_idx": {
|
||||
"name": "image_idx",
|
||||
"columns": [
|
||||
"image"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"users_group_id_groups_id_fk": {
|
||||
"name": "users_group_id_groups_id_fk",
|
||||
"tableFrom": "users",
|
||||
"tableTo": "groups",
|
||||
"columnsFrom": [
|
||||
"group_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"users_zone_id_zones_id_fk": {
|
||||
"name": "users_zone_id_zones_id_fk",
|
||||
"tableFrom": "users",
|
||||
"tableTo": "zones",
|
||||
"columnsFrom": [
|
||||
"zone_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"user_opinions": {
|
||||
"name": "user_opinions",
|
||||
"columns": {
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"opinion_id": {
|
||||
"name": "opinion_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"choice": {
|
||||
"name": "choice",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'ignore'"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"user_opinions_user_id_users_id_fk": {
|
||||
"name": "user_opinions_user_id_users_id_fk",
|
||||
"tableFrom": "user_opinions",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"user_opinions_opinion_id_opinions_id_fk": {
|
||||
"name": "user_opinions_opinion_id_opinions_id_fk",
|
||||
"tableFrom": "user_opinions",
|
||||
"tableTo": "opinions",
|
||||
"columnsFrom": [
|
||||
"opinion_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {
|
||||
"user_opinions_user_id_opinion_id_pk": {
|
||||
"columns": [
|
||||
"opinion_id",
|
||||
"user_id"
|
||||
],
|
||||
"name": "user_opinions_user_id_opinion_id_pk"
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"user_to_selection": {
|
||||
"name": "user_to_selection",
|
||||
"columns": {
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"target_id": {
|
||||
"name": "target_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"user_to_selection_user_id_users_id_fk": {
|
||||
"name": "user_to_selection_user_id_users_id_fk",
|
||||
"tableFrom": "user_to_selection",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"user_to_selection_target_id_users_id_fk": {
|
||||
"name": "user_to_selection_target_id_users_id_fk",
|
||||
"tableFrom": "user_to_selection",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"target_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"zones": {
|
||||
"name": "zones",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"province_id": {
|
||||
"name": "province_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"total": {
|
||||
"name": "total",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"zones_name_province_id_unique": {
|
||||
"name": "zones_name_province_id_unique",
|
||||
"columns": [
|
||||
"name",
|
||||
"province_id"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"zones_province_id_provinces_id_fk": {
|
||||
"name": "zones_province_id_provinces_id_fk",
|
||||
"tableFrom": "zones",
|
||||
"tableTo": "provinces",
|
||||
"columnsFrom": [
|
||||
"province_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,13 @@
|
||||
"when": 1717814164478,
|
||||
"tag": "0000_tired_impossible_man",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "5",
|
||||
"when": 1717817049392,
|
||||
"tag": "0001_last_hiroim",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -81,7 +81,7 @@ export const userRoute = router({
|
||||
.input(
|
||||
z.object({
|
||||
offset: z.number().default(0),
|
||||
limit: z.number().max(50).default(10),
|
||||
limit: z.number().max(1000).default(1000),
|
||||
group: z.number().optional(),
|
||||
zone: z.number().optional(),
|
||||
opinionCount: z.number().default(3),
|
||||
@@ -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,8 +187,21 @@ async function getAllUser(
|
||||
with: { province: true },
|
||||
},
|
||||
},
|
||||
limit: 3,
|
||||
limit: 10,
|
||||
orderBy: user.rank,
|
||||
where: (user, { eq, and }) => {
|
||||
const conditions: SQL[] = [];
|
||||
if (group !== undefined) {
|
||||
conditions.push(eq(user.group, group));
|
||||
}
|
||||
if (zoneId !== undefined) {
|
||||
conditions.push(eq(user.zone, zoneId));
|
||||
}
|
||||
if (zoneIds.length > 0) {
|
||||
conditions.push(inArray(user.zone, zoneIds));
|
||||
}
|
||||
return and(...conditions);
|
||||
},
|
||||
});
|
||||
let users = await db.query.user.findMany({
|
||||
with: {
|
||||
@@ -228,18 +241,28 @@ async function getAllUser(
|
||||
}
|
||||
resultUser = [
|
||||
...validSelection,
|
||||
...users.filter((u) => !validSelection.includes(u)),
|
||||
...users.filter(
|
||||
(u) => validSelection.filter((v) => v.id == u.id).length == 0,
|
||||
),
|
||||
];
|
||||
resultUser = randomArray(1, 10, resultUser);
|
||||
} else {
|
||||
resultUser = [...topThree, ...users.filter((u) => !topThree.includes(u))];
|
||||
resultUser = [
|
||||
...topTen,
|
||||
...users.filter((u) => topTen.filter((v) => v.id == u.id).length == 0),
|
||||
];
|
||||
resultUser = randomArray(0, 5, resultUser);
|
||||
resultUser = randomArray(5, 10, resultUser);
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -485,3 +508,11 @@ async function getZone(province?: number) {
|
||||
.then((queryResult) => queryResult.map((v) => v.id));
|
||||
return zoneIds;
|
||||
}
|
||||
|
||||
function randomArray<T>(from: number, to: number, arr: T[]): T[] {
|
||||
for (let i = Math.min(arr.length - 1, from); i < to; i++) {
|
||||
const j = Math.floor(Math.random() * (i - from)) + from;
|
||||
[arr[i], arr[j]] = [arr[j], arr[i]];
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user