-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c88958
commit d4e2549
Showing
11 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ yarn-error.log* | |
|
||
# local env files | ||
.env*.local | ||
|
||
/.env | ||
# vercel | ||
.vercel | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import mongoose from "mongoose"; | ||
|
||
type ConnectionObject = { | ||
isConnected?:number | ||
} | ||
const connection: ConnectionObject = {} | ||
|
||
export const dbconnect = async (): Promise<void> => { | ||
if (connection.isConnected) { | ||
console.log('Already connected to database'); | ||
return | ||
} | ||
try { | ||
const db = await mongoose.connect(process.env.MONGODB_URI!||'',{}); | ||
connection.isConnected = db.connections[0].readyState | ||
|
||
console.log('DB connected succefully '); | ||
|
||
} catch (error: any) { | ||
|
||
console.log('Somthing went wrong with db connecton falied',error); | ||
process.exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import mongoose, { Document, Schema } from "mongoose"; | ||
|
||
export interface Message extends Document{ | ||
content: string, | ||
createdAt:Date, | ||
} | ||
const MessageSchema: Schema<Message> = new Schema({ | ||
content: { | ||
type: String, | ||
required:true | ||
}, | ||
createdAt: { | ||
type: Date, | ||
required: true, | ||
default:Date.now | ||
} | ||
}) | ||
export interface User extends Document{ | ||
username: string, | ||
email: string, | ||
password: string, | ||
verifyCode: string, | ||
verifyCOdeExpiry: Date, | ||
isAcceptingMessage: boolean, | ||
isverifiedd:boolean, | ||
message:Message[], | ||
} | ||
const UserSchema: Schema<User> = new Schema({ | ||
email: { | ||
type: String, | ||
required: [true, "email is reuired"], | ||
unique: true, | ||
// email testing | ||
match:[/.+\@.+\..+/,'please use a valid email address '] | ||
}, | ||
|
||
username: { | ||
type: String, | ||
required: [true, "Username is reuired"], | ||
unique: true, | ||
trim:true, | ||
}, | ||
password: { | ||
type: String, | ||
required: [true, "password is reuired"], | ||
}, | ||
verifyCode: { | ||
type: String, | ||
required: [true, "verifycode is reuired"], | ||
}, | ||
verifyCOdeExpiry: { | ||
type: Date, | ||
required: [true, "verifycodeexpiry is reuired"], | ||
}, | ||
isverifiedd: { | ||
type: Boolean, | ||
default:false, | ||
|
||
}, | ||
isAcceptingMessage: { | ||
type: Boolean, | ||
default:true, | ||
}, | ||
message: [MessageSchema] | ||
|
||
|
||
}) | ||
|
||
const UserModel = mongoose.models.User as mongoose.Model<User> || mongoose.model<User>("User",UserSchema) | ||
|
||
export default UserModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { z } from "zod" | ||
|
||
export const acceptMessageSchema = z.object({ | ||
acceptMessages:z.boolean(), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
import { z } from "zod" | ||
|
||
export const MessageSchema = z.object({ | ||
content: z | ||
.string() | ||
.min(10, 'content must be atleast of 10 character ') | ||
.max(300,'content must be atmost of 300 character '), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { z } from "zod" | ||
|
||
export const SignInSchema = z.object({ | ||
identifier: z.string(), | ||
password:z.string() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { z } from 'zod' | ||
|
||
export const usernameValidation = z | ||
.string() | ||
.min(2, "Username must be atleast 2 charcaters") | ||
.max(20, "Usernaem must be at most 20 character") | ||
.regex(/^[a-zA-Z0-9_]+$/, "Usrname must not conatain special cahracter ") | ||
|
||
export const signUpSchema = z.object({ | ||
username: usernameValidation, | ||
email: z.string().email({message:'Invalid email address'}), | ||
password: z.string().min(6, { message:"password must be atleast 6 character"}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { z } from "zod" | ||
|
||
export const verifySchema = z.object({ | ||
code:z.string().length(6,'verification code of 6 digits') | ||
}) |