Skip to content

Commit

Permalink
resolved errors during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
arogya01 committed Sep 22, 2024
1 parent 86d3db9 commit 1117346
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
20 changes: 8 additions & 12 deletions src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyReply, FastifyRequest } from "fastify";
import { CreateUserInput, LoginUserInput } from "./user.schema";
import { checkExistingUser, createUser, fetchUserByUserId } from "./user.service";
import { checkExistingUser, createUser, fetchUserByEmail } from "./user.service";
import { verifyPassword } from "../../utils/hash";

export const loginHandler = async (
Expand Down Expand Up @@ -65,17 +65,12 @@ export const getUsersHandler = () => {



interface DecodedToken {
userId: string;
interface DecodedToken {
[key: string]: any;
}

export const getUserProfileHandler = async (
request: FastifyRequest<{
Querystring: {
accessToken: string;
};
}>,
request: FastifyRequest,
reply: FastifyReply
) => {
console.log("getUserProfileHandler");
Expand Down Expand Up @@ -103,14 +98,15 @@ export const getUserProfileHandler = async (
return;
}

const userId = decodedToken.userId;
if (!userId) {
reply.code(401).send({ error: 'UserId not found in token' });
const email = decodedToken.email;
if (!email) {
reply.code(401).send({ error: 'user details not found in token' });
return;
}

// Find the user in the database
const user = await fetchUserByUserId(Number(userId));
const user = await fetchUserByEmail(email);
console.log('got the user',user);
if (!user) {
reply.code(404).send({ error: 'User not found' });
return;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/user/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const getUserProfileSchema = z.object({
});

const getUserProfileRespSchema = z.object({
id: z.number(),
userId: z.number(),
userName: z.string(),
email: z.string(),
phoneNumber: z.string(),
Expand Down
13 changes: 5 additions & 8 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ export const createUser = async (requestBody: CreateUserInput) => {

export const verifyPassword = async () => {};

export const fetchUserByUserId = async (userId:number) => {
console.log('fetching user by id', userId);
export const fetchUserByEmail = async (email:string) => {
console.log('fetching user by id', email);
const userProfile = await prisma.profile.findUnique({
where: {
userId : userId
},
include:{
user:true
}
email:email
},
});

console.log('userProifle,', userProfile);
console.log('userProfile,', userProfile);

return userProfile;

Expand Down

0 comments on commit 1117346

Please sign in to comment.