feat: connect UI texts, address CRUD, OTP autofocus and profile to backend
This commit is contained in:
1 parent
4e2c8d5cfe
commit
467532713c
82 files changed
+14436
-274
No files matched your search
@@ -0,0 +1,111 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findById(id: string) {
|
||||
return this.prisma.user.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
pets: true,
|
||||
orders: {
|
||||
include: {
|
||||
orderItems: {
|
||||
include: { product: true }
|
||||
}
|
||||
}
|
||||
},
|
||||
addresses: true,
|
||||
walletTransactions: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async update(id: string, data: any) {
|
||||
return this.prisma.user.update({
|
||||
where: { id },
|
||||
data,
|
||||
include: {
|
||||
pets: true,
|
||||
orders: {
|
||||
include: {
|
||||
orderItems: {
|
||||
include: { product: true }
|
||||
}
|
||||
}
|
||||
},
|
||||
addresses: true,
|
||||
walletTransactions: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async addAddress(userId: string, data: any) {
|
||||
if (data.isDefault) {
|
||||
await this.prisma.userAddress.updateMany({
|
||||
where: { userId },
|
||||
data: { isDefault: false },
|
||||
});
|
||||
}
|
||||
return this.prisma.userAddress.create({
|
||||
data: {
|
||||
title: data.title,
|
||||
receptorName: data.receptorName,
|
||||
phone: data.phone,
|
||||
province: data.province,
|
||||
city: data.city,
|
||||
detail: data.detail,
|
||||
zipCode: data.zipCode,
|
||||
isDefault: data.isDefault || false,
|
||||
userId: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async updateAddress(userId: string, addressId: string, data: any) {
|
||||
if (data.isDefault) {
|
||||
await this.prisma.userAddress.updateMany({
|
||||
where: { userId, NOT: { id: addressId } },
|
||||
data: { isDefault: false },
|
||||
});
|
||||
}
|
||||
return this.prisma.userAddress.update({
|
||||
where: { id: addressId, userId },
|
||||
data: {
|
||||
title: data.title,
|
||||
receptorName: data.receptorName,
|
||||
phone: data.phone,
|
||||
province: data.province,
|
||||
city: data.city,
|
||||
detail: data.detail,
|
||||
zipCode: data.zipCode,
|
||||
isDefault: data.isDefault || false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async deleteAddress(userId: string, addressId: string) {
|
||||
return this.prisma.userAddress.delete({
|
||||
where: { id: addressId, userId },
|
||||
});
|
||||
}
|
||||
|
||||
async setDefaultAddress(userId: string, addressId: string) {
|
||||
await this.prisma.userAddress.updateMany({
|
||||
where: { userId },
|
||||
data: { isDefault: false },
|
||||
});
|
||||
return this.prisma.userAddress.update({
|
||||
where: { id: addressId, userId },
|
||||
data: { isDefault: true },
|
||||
});
|
||||
}
|
||||
|
||||
async findByPhone(phoneNumber: string) {
|
||||
return this.prisma.user.findUnique({
|
||||
where: { mobile: phoneNumber },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user