Passenger portal and api updates

This commit is contained in:
Stephanos A
2026-06-03 15:36:37 +03:00
parent 6f4ce7d49a
commit f4051aadfc
28 changed files with 1874 additions and 371 deletions

View File

@@ -62,7 +62,21 @@ export class AuthService {
});
await this.createAuditLog(user.id, 'USER_LOGIN', 'User', user.id, null, null);
return await this.signToken(user.id, user.email, user.role, user.passenger?.id, user.agent?.id);
// Ensure passenger exists and get its ID
let passengerId = user.passenger?.id;
if (!passengerId) {
// If passenger doesn't exist, create it
const passenger = await this.prisma.passenger.create({
data: { userId: user.id }
});
passengerId = passenger.id;
// Also create loyalty and wallet accounts
await this.prisma.loyaltyAccount.create({ data: { passengerId: passenger.id } });
await this.prisma.walletAccount.create({ data: { passengerId: passenger.id } });
}
return await this.signToken(user.id, user.email, user.role, passengerId, user.agent?.id);
}
async requestOtp(dto: RequestOtpDto) {
@@ -124,8 +138,13 @@ export class AuthService {
select: { id: true, email: true, fullName: true, role: true }
});
const token = this.jwt.sign({ sub: userId, email, role, passengerId, agentId });
return {
const payload = { sub: userId, email, role, passengerId, agentId };
console.log('[AUTH] Creating JWT with payload:', payload);
const token = this.jwt.sign(payload);
console.log('[AUTH] JWT created, token length:', token.length);
const response = {
token,
user: {
id: userId,
@@ -136,6 +155,8 @@ export class AuthService {
agentId
}
};
console.log('[AUTH] Returning user object with passengerId:', response.user.passengerId);
return response;
}
private async createAuditLog(userId: string, action: string, entityType: string, entityId: string, oldData: any, newData: any) {