Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: send message
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRouyer committed Sep 10, 2023
1 parent 8af3ab4 commit 56897f4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ export const MessageForm: FC = () => {
status: MessageStatus.Pending,
content: data.content,
createdAt: new Date(),
senderId: currentUser?.contactId ?? 0,
sender: {
id: currentUser?.id ?? '',
name: currentUser?.fullName,
avatarUrl: currentUser?.image,
id: currentUser?.contactId ?? 0,
name: currentUser?.name ?? '',
email: currentUser?.email ?? '',
avatarUrl: currentUser?.image ?? '',
createdAt: new Date(),
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { User } from '~/hooks/useTicket/User';
import { api } from '~/utils/api';

export type SendMessageParams = {
message: Omit<Message, 'id'>;
message: Omit<Message, 'id'> & { senderId: number };
ticketId: TicketId;
};

Expand Down
3 changes: 2 additions & 1 deletion apps/customer-service/src/hooks/useTicket/TicketStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class TicketStorage {
user.id,
user.name ?? '',
user.email ?? '',
user.image ?? undefined
user.image ?? undefined,
user.contactId
);
}

Expand Down
10 changes: 9 additions & 1 deletion apps/customer-service/src/hooks/useTicket/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ export class User {
name: string;
email: string;
image?: string;
contactId?: number;

constructor(id: UserId, name: string, email: string, image?: string) {
constructor(
id: UserId,
name: string,
email: string,
image?: string,
contactId?: number
) {
this.id = id;
this.name = name;
this.email = email;
this.image = image;
this.contactId = contactId;
}

get fullName() {
Expand Down
15 changes: 14 additions & 1 deletion apps/customer-service/src/utils/session.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { auth } from '@cs/auth';
import { db, eq, schema } from '@cs/database';

export async function getCurrentUser() {
const session = await auth();

return session?.user;
if (!session) {
return null;
}

// TODO: refactor when auth session callback works
const user = await db.query.users.findFirst({
where: eq(schema.users.id, session.user.id),
});

return {
...session?.user,
contactId: user?.contactId,
};
}
1 change: 1 addition & 0 deletions packages/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare module 'next-auth' {
interface Session {
user: {
id: string;
contactId?: number;
} & DefaultSession['user'];
}
}
Expand Down

0 comments on commit 56897f4

Please sign in to comment.