Skip to content

Commit 740db31

Browse files
committed
update code
1 parent 2fd6325 commit 740db31

8 files changed

+47
-34
lines changed

components/forms/AccountProfile.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ const AccountProfile = ({ user, btnTitle }: Props) => {
6666
}
6767
}
6868

69-
await updateUser(
70-
values.username,
71-
values.name,
72-
values.bio,
73-
values.profile_photo,
74-
user.id,
75-
pathname
76-
);
69+
await updateUser({
70+
name: values.name,
71+
path: pathname,
72+
username: values.username,
73+
userId: user.id,
74+
bio: values.bio,
75+
image: values.profile_photo,
76+
});
7777

7878
if (pathname === "/profile/edit") {
7979
router.back();

components/forms/PostThread.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface Props {
2626

2727
function PostThread({ userId }: Props) {
2828
const router = useRouter();
29-
const pathName = usePathname();
29+
const pathname = usePathname();
3030

3131
const { organization } = useOrganization();
3232

@@ -39,11 +39,12 @@ function PostThread({ userId }: Props) {
3939
});
4040

4141
const onSubmit = async (values: z.infer<typeof ThreadValidation>) => {
42-
if (!organization) {
43-
await createThread(values.thread, userId, null, pathName);
44-
} else {
45-
await createThread(values.thread, userId, organization.id, pathName);
46-
}
42+
await createThread({
43+
text: values.thread,
44+
author: userId,
45+
communityId: organization ? organization.id : null,
46+
path: pathname,
47+
});
4748

4849
router.push("/");
4950
};

lib/actions/community.actions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import { FilterQuery, SortOrder } from "mongoose";
44

5-
import Community from "@/mongodb/community.model";
6-
import Thread from "@/mongodb/thread.model";
7-
import User from "@/mongodb/user.model";
5+
import Community from "../models/community.model";
6+
import Thread from "../models/thread.model";
7+
import User from "../models/user.model";
88

99
import { connectToDB } from "../mongoose";
1010

lib/actions/thread.actions.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { revalidatePath } from "next/cache";
44

55
import { connectToDB } from "../mongoose";
66

7-
import User from "@/mongodb/user.model";
8-
import Thread from "@/mongodb/thread.model";
9-
import Community from "@/mongodb/community.model";
7+
import User from "../models/user.model";
8+
import Thread from "../models/thread.model";
9+
import Community from "../models/community.model";
1010

1111
export async function fetchPosts(pageNumber = 1, pageSize = 20) {
1212
connectToDB();
@@ -48,11 +48,14 @@ export async function fetchPosts(pageNumber = 1, pageSize = 20) {
4848
return { posts, isNext };
4949
}
5050

51-
export async function createThread(
51+
interface Params {
5252
text: string,
5353
author: string,
54-
communityId: string | null, // Nullable communityId to indicate personal account
55-
path: string
54+
communityId: string | null,
55+
path: string,
56+
}
57+
58+
export async function createThread({ text, author, communityId, path }: Params
5659
) {
5760
try {
5861
connectToDB();

lib/actions/user.actions.ts

+20-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import { FilterQuery, SortOrder } from "mongoose";
44
import { revalidatePath } from "next/cache";
55

6-
import Community from "@/mongodb/community.model";
7-
import Thread from "@/mongodb/thread.model";
8-
import User from "@/mongodb/user.model";
6+
import Community from "../models/community.model";
7+
import Thread from "../models/thread.model";
8+
import User from "../models/user.model";
99

1010
import { connectToDB } from "../mongoose";
1111

@@ -22,14 +22,23 @@ export async function fetchUser(userId: string) {
2222
}
2323
}
2424

25-
export async function updateUser(
26-
username: string,
27-
name: string,
28-
bio: string,
29-
image: string,
30-
userId: string,
31-
path: string
32-
): Promise<void> {
25+
interface Params {
26+
userId: string;
27+
username: string;
28+
name: string;
29+
bio: string;
30+
image: string;
31+
path: string;
32+
}
33+
34+
export async function updateUser({
35+
userId,
36+
bio,
37+
name,
38+
path,
39+
username,
40+
image,
41+
}: Params): Promise<void> {
3342
try {
3443
connectToDB();
3544

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)