This commit is contained in:
@@ -2,12 +2,19 @@ import { db } from "@/src/db";
|
||||
import LocationSelector from "../../components/LocationSelector";
|
||||
import LocationContextProvider from "@/components/locationContext";
|
||||
import GroupCreator from "./GroupCreator";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { user } from "@/src/schema";
|
||||
|
||||
export default async function Page() {
|
||||
const provinces = await db.query.province
|
||||
.findMany({ with: { zones: true } })
|
||||
.execute();
|
||||
const jobList = await db.query.group.findMany().execute();
|
||||
let r = await db.query.user
|
||||
.findMany({ columns: { id: true }, where: eq(user.verified, true) })
|
||||
.execute()
|
||||
.then((v) => v.length);
|
||||
console.log(r);
|
||||
return (
|
||||
<LocationContextProvider>
|
||||
<LocationSelector provinces={provinces} />
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
"use server";
|
||||
import { db } from "@/src/db";
|
||||
import { user } from "@/src/schema";
|
||||
import { inArray } from "drizzle-orm";
|
||||
|
||||
export async function saveUser(ids: string[]) {
|
||||
console.log(ids);
|
||||
} //TODO: submit inside user
|
||||
export async function saveUser(cids: string[]) {
|
||||
let rs = await db
|
||||
.update(user)
|
||||
.set({ verified: true })
|
||||
.where(inArray(user.cid, cids))
|
||||
.execute();
|
||||
return rs;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import IdComponent from "./IdComponent";
|
||||
export default function Page() {
|
||||
const [idList, setIdList] = useState<string[]>([]);
|
||||
async function submit() {
|
||||
await saveUser(idList);
|
||||
alert("อัพเดทสำเร็จ");
|
||||
let rs = await saveUser(idList);
|
||||
alert(`อัพเดทสำเร็จ ${rs.changes} คน`);
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
|
||||
47
app/total/TotalSetter.tsx
Normal file
47
app/total/TotalSetter.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
"use client";
|
||||
|
||||
import { LocationContext } from "@/components/locationContext";
|
||||
import { useContext, useState } from "react";
|
||||
import { updateZone } from "./action";
|
||||
|
||||
export default function TotalSetter() {
|
||||
const locationContext = useContext(LocationContext);
|
||||
const [total, setTotal] = useState<number>(0);
|
||||
async function submit() {
|
||||
if (
|
||||
locationContext?.zone[0] == undefined ||
|
||||
locationContext?.province[0] == undefined
|
||||
) {
|
||||
alert("ยังไม่ได้เลือกพื้นที่");
|
||||
return;
|
||||
}
|
||||
await updateZone(
|
||||
locationContext.province[0],
|
||||
locationContext.zone[0],
|
||||
total,
|
||||
);
|
||||
alert(`อัพเดทสำเร็จ`);
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<div className="flex">
|
||||
จำนวนทั้งหมด:{" "}
|
||||
<input
|
||||
value={total}
|
||||
className="rounded-md border-2"
|
||||
type="number"
|
||||
onChange={(e) =>
|
||||
setTotal(
|
||||
e.currentTarget.value !== ""
|
||||
? parseInt(e.currentTarget.value)
|
||||
: 0,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<button className="rounded-md bg-green-300 p-2" onClick={submit}>
|
||||
ยืนยัน
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
20
app/total/action.ts
Normal file
20
app/total/action.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
"use server";
|
||||
|
||||
export type JobCategory = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type Group = {
|
||||
id: number;
|
||||
jobs: number[];
|
||||
};
|
||||
|
||||
//TODO: submit group
|
||||
export async function updateZone(
|
||||
province: number,
|
||||
zone: number,
|
||||
total: number,
|
||||
) {
|
||||
console.log({ province, zone, total });
|
||||
}
|
||||
24
app/total/page.tsx
Normal file
24
app/total/page.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { db } from "@/src/db";
|
||||
import LocationSelector from "../../components/LocationSelector";
|
||||
import LocationContextProvider from "@/components/locationContext";
|
||||
import TotalSetter from "./TotalSetter";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { user } from "@/src/schema";
|
||||
|
||||
export default async function Page() {
|
||||
const provinces = await db.query.province
|
||||
.findMany({ with: { zones: true } })
|
||||
.execute();
|
||||
const jobList = await db.query.group.findMany().execute();
|
||||
let r = await db.query.user
|
||||
.findMany({ columns: { id: true }, where: eq(user.verified, true) })
|
||||
.execute()
|
||||
.then((v) => v.length);
|
||||
console.log(r);
|
||||
return (
|
||||
<LocationContextProvider>
|
||||
<LocationSelector provinces={provinces} />
|
||||
<TotalSetter />
|
||||
</LocationContextProvider>
|
||||
);
|
||||
}
|
||||
1
drizzle/0004_icy_blockbuster.sql
Normal file
1
drizzle/0004_icy_blockbuster.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE zones ADD `total` integer DEFAULT 0 NOT NULL;
|
||||
507
drizzle/meta/0004_snapshot.json
Normal file
507
drizzle/meta/0004_snapshot.json
Normal file
@@ -0,0 +1,507 @@
|
||||
{
|
||||
"version": "5",
|
||||
"dialect": "sqlite",
|
||||
"id": "186f6e92-2b24-4aa0-8a01-68534b1997a3",
|
||||
"prevId": "e867b430-8022-40ca-9151-eab2690479e1",
|
||||
"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
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"users_cid_unique": {
|
||||
"name": "users_cid_unique",
|
||||
"columns": [
|
||||
"cid"
|
||||
],
|
||||
"isUnique": true
|
||||
},
|
||||
"users_phone_unique": {
|
||||
"name": "users_phone_unique",
|
||||
"columns": [
|
||||
"phone"
|
||||
],
|
||||
"isUnique": true
|
||||
},
|
||||
"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": {}
|
||||
},
|
||||
"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": {}
|
||||
}
|
||||
}
|
||||
@@ -1 +1,41 @@
|
||||
{"version":"5","dialect":"sqlite","entries":[{"idx":0,"version":"5","when":1713548458041,"tag":"0000_right_nebula","breakpoints":true},{"idx":1,"version":"5","when":1713599233997,"tag":"0001_chilly_bullseye","breakpoints":true},{"idx":2,"version":"5","when":1715319087385,"tag":"0002_gigantic_sentry","breakpoints":true},{"idx":3,"version":"5","when":1715935487997,"tag":"0003_overconfident_spencer_smythe","breakpoints":true}]}
|
||||
{
|
||||
"version": "5",
|
||||
"dialect": "sqlite",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "5",
|
||||
"when": 1713548458041,
|
||||
"tag": "0000_right_nebula",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "5",
|
||||
"when": 1713599233997,
|
||||
"tag": "0001_chilly_bullseye",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "5",
|
||||
"when": 1715319087385,
|
||||
"tag": "0002_gigantic_sentry",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "5",
|
||||
"when": 1715935487997,
|
||||
"tag": "0003_overconfident_spencer_smythe",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "5",
|
||||
"when": 1716192353702,
|
||||
"tag": "0004_icy_blockbuster",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -118,6 +118,7 @@ export const zone = sqliteTable(
|
||||
province: integer("province_id")
|
||||
.notNull()
|
||||
.references(() => province.id),
|
||||
total: integer("total").notNull().default(0),
|
||||
},
|
||||
(t) => ({ unique_name_province: unique().on(t.name, t.province) }),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user