add more detail to user
This commit is contained in:
@@ -5,4 +5,5 @@ export const Config = {
|
|||||||
sms_api_verify_endpoint: "https://otp.thaibulksms.com/v2/otp/verify",
|
sms_api_verify_endpoint: "https://otp.thaibulksms.com/v2/otp/verify",
|
||||||
jwt_secret:
|
jwt_secret:
|
||||||
"T4kE6/tIqCVEZYg9lwsqeJjYfOoXTXSXDEMyParsJjj57CjSdkrfPOLWP74/9lJpcBA=",
|
"T4kE6/tIqCVEZYg9lwsqeJjYfOoXTXSXDEMyParsJjj57CjSdkrfPOLWP74/9lJpcBA=",
|
||||||
|
token_duration: "365d",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,28 +4,42 @@ import {
|
|||||||
integer,
|
integer,
|
||||||
primaryKey,
|
primaryKey,
|
||||||
unique,
|
unique,
|
||||||
|
index,
|
||||||
} from "drizzle-orm/sqlite-core";
|
} from "drizzle-orm/sqlite-core";
|
||||||
import { relations, sql } from "drizzle-orm";
|
import { relations, sql } from "drizzle-orm";
|
||||||
|
|
||||||
//----------------User
|
//----------------User
|
||||||
export const user = sqliteTable("users", {
|
export const user = sqliteTable(
|
||||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
"users",
|
||||||
firstName: text("firstName").notNull(),
|
{
|
||||||
lastName: text("lastName").notNull(),
|
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||||
title: text("title").notNull(),
|
firstName: text("firstName").notNull(),
|
||||||
phone: text("phone").unique().notNull(),
|
lastName: text("lastName").notNull(),
|
||||||
email: text("email"),
|
title: text("title").notNull(),
|
||||||
job: text("job").notNull(),
|
cid: text("cid", { length: 13 }).notNull().unique(),
|
||||||
education: text("education").notNull(),
|
age: integer("age").notNull(),
|
||||||
vision: text("vision"),
|
phone: text("phone").unique().notNull(),
|
||||||
reason: text("reason"),
|
public_phone: text("public_phone"),
|
||||||
group: integer("group_id")
|
facebook: text("facebook"),
|
||||||
.references(() => group.id)
|
twitter: text("twitter"),
|
||||||
.notNull(),
|
tiktok: text("tiktok"),
|
||||||
zone: integer("zone_id")
|
otherSocial: text("other_social"),
|
||||||
.notNull()
|
email: text("email"),
|
||||||
.references(() => zone.id),
|
job: text("job").notNull(),
|
||||||
});
|
education: text("education").notNull(),
|
||||||
|
vision: text("vision"),
|
||||||
|
reason: text("reason"),
|
||||||
|
group: integer("group_id")
|
||||||
|
.references(() => group.id)
|
||||||
|
.notNull(),
|
||||||
|
zone: integer("zone_id")
|
||||||
|
.notNull()
|
||||||
|
.references(() => zone.id),
|
||||||
|
},
|
||||||
|
(t) => ({
|
||||||
|
phone_idx: index("phone_idx").on(t.phone),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
export const userRelation = relations(user, ({ many, one }) => ({
|
export const userRelation = relations(user, ({ many, one }) => ({
|
||||||
opinions: many(userOpinion),
|
opinions: many(userOpinion),
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import { Config } from "./config";
|
|||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import * as jwt from "jsonwebtoken";
|
import * as jwt from "jsonwebtoken";
|
||||||
|
|
||||||
const userInsertSchema = createInsertSchema(user);
|
const userInsertSchema = createInsertSchema(user, {
|
||||||
|
cid: (schema) => schema.cid.length(13),
|
||||||
|
});
|
||||||
const opinionInsertSchema = createInsertSchema(userOpinion)
|
const opinionInsertSchema = createInsertSchema(userOpinion)
|
||||||
.omit({
|
.omit({
|
||||||
userId: true,
|
userId: true,
|
||||||
@@ -190,7 +192,7 @@ async function verifyOtp(token: string, pin: string) {
|
|||||||
} else {
|
} else {
|
||||||
await db.delete(phoneToken).where(eq(phoneToken.phone, pt.phone));
|
await db.delete(phoneToken).where(eq(phoneToken.phone, pt.phone));
|
||||||
const token = jwt.sign({ phone: pt.phone }, Config.jwt_secret, {
|
const token = jwt.sign({ phone: pt.phone }, Config.jwt_secret, {
|
||||||
expiresIn: "3d",
|
expiresIn: "365d",
|
||||||
});
|
});
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user