first
This commit is contained in:
commit
0fa3c7ac48
140 files changed
+24289
No files matched your search
+139
@@ -0,0 +1,139 @@
|
||||
import { UserService } from './user.service';
|
||||
export declare class UserController {
|
||||
private readonly userService;
|
||||
constructor(userService: UserService);
|
||||
getWatchlist(userId: string): Promise<({
|
||||
product: {
|
||||
prices: ({
|
||||
source: {
|
||||
id: number;
|
||||
name: string;
|
||||
url: string;
|
||||
logo: string | null;
|
||||
lastScraped: Date | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
} & {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
sourceId: number;
|
||||
regularPrice: number;
|
||||
discountedPrice: number | null;
|
||||
discountPercentage: number | null;
|
||||
unitPrice: string | null;
|
||||
promotionType: string | null;
|
||||
promotionStart: Date | null;
|
||||
promotionEnd: Date | null;
|
||||
vatIncluded: boolean;
|
||||
lastUpdated: Date;
|
||||
productId: number;
|
||||
})[];
|
||||
} & {
|
||||
id: number;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
description: string | null;
|
||||
category: string;
|
||||
availability: boolean;
|
||||
sourceProductId: string | null;
|
||||
sourceId: number;
|
||||
};
|
||||
} & {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
})[]>;
|
||||
addToWatchlist(userId: string, data: {
|
||||
productId: number;
|
||||
}): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
}>;
|
||||
removeFromWatchlist(userId: string, productId: string): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
}>;
|
||||
getNotifications(userId: string): Promise<({
|
||||
product: {
|
||||
prices: ({
|
||||
source: {
|
||||
id: number;
|
||||
name: string;
|
||||
url: string;
|
||||
logo: string | null;
|
||||
lastScraped: Date | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
} & {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
sourceId: number;
|
||||
regularPrice: number;
|
||||
discountedPrice: number | null;
|
||||
discountPercentage: number | null;
|
||||
unitPrice: string | null;
|
||||
promotionType: string | null;
|
||||
promotionStart: Date | null;
|
||||
promotionEnd: Date | null;
|
||||
vatIncluded: boolean;
|
||||
lastUpdated: Date;
|
||||
productId: number;
|
||||
})[];
|
||||
} & {
|
||||
id: number;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
description: string | null;
|
||||
category: string;
|
||||
availability: boolean;
|
||||
sourceProductId: string | null;
|
||||
sourceId: number;
|
||||
};
|
||||
} & {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
priceThreshold: number | null;
|
||||
percentThreshold: number | null;
|
||||
notifyOnAnyChange: boolean;
|
||||
isActive: boolean;
|
||||
})[]>;
|
||||
configureNotification(userId: string, data: {
|
||||
productId: number;
|
||||
priceThreshold?: number;
|
||||
percentThreshold?: number;
|
||||
notifyOnAnyChange?: boolean;
|
||||
}): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
priceThreshold: number | null;
|
||||
percentThreshold: number | null;
|
||||
notifyOnAnyChange: boolean;
|
||||
isActive: boolean;
|
||||
}>;
|
||||
removeNotification(userId: string, productId: string): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
priceThreshold: number | null;
|
||||
percentThreshold: number | null;
|
||||
notifyOnAnyChange: boolean;
|
||||
isActive: boolean;
|
||||
}>;
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const user_service_1 = require("./user.service");
|
||||
let UserController = class UserController {
|
||||
userService;
|
||||
constructor(userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
async getWatchlist(userId) {
|
||||
return this.userService.getWatchlist(Number(userId));
|
||||
}
|
||||
async addToWatchlist(userId, data) {
|
||||
return this.userService.addToWatchlist(Number(userId), data.productId);
|
||||
}
|
||||
async removeFromWatchlist(userId, productId) {
|
||||
return this.userService.removeFromWatchlist(Number(userId), Number(productId));
|
||||
}
|
||||
async getNotifications(userId) {
|
||||
return this.userService.getNotifications(Number(userId));
|
||||
}
|
||||
async configureNotification(userId, data) {
|
||||
return this.userService.configureNotification(Number(userId), data);
|
||||
}
|
||||
async removeNotification(userId, productId) {
|
||||
return this.userService.removeNotification(Number(userId), Number(productId));
|
||||
}
|
||||
};
|
||||
exports.UserController = UserController;
|
||||
__decorate([
|
||||
(0, common_1.Get)(':userId/watchlist'),
|
||||
__param(0, (0, common_1.Param)('userId')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "getWatchlist", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)(':userId/watchlist'),
|
||||
__param(0, (0, common_1.Param)('userId')),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "addToWatchlist", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(':userId/watchlist/:productId'),
|
||||
__param(0, (0, common_1.Param)('userId')),
|
||||
__param(1, (0, common_1.Param)('productId')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, String]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "removeFromWatchlist", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)(':userId/notifications'),
|
||||
__param(0, (0, common_1.Param)('userId')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "getNotifications", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)(':userId/notifications'),
|
||||
__param(0, (0, common_1.Param)('userId')),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "configureNotification", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(':userId/notifications/:productId'),
|
||||
__param(0, (0, common_1.Param)('userId')),
|
||||
__param(1, (0, common_1.Param)('productId')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, String]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "removeNotification", null);
|
||||
exports.UserController = UserController = __decorate([
|
||||
(0, common_1.Controller)('users'),
|
||||
__metadata("design:paramtypes", [user_service_1.UserService])
|
||||
], UserController);
|
||||
//# sourceMappingURL=user.controller.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"user.controller.js","sourceRoot":"","sources":["../../src/user/user.controller.ts"],"names":[],"mappings":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A,cAAK,EAAC,QAAQ,CAAC,CAAA;;;;kDAElC;AAGK;IADL,IAAA,aAAI,EAAC,mBAAmB,CAAC;IAEvB,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;IACf,WAAA,IAAA,aAAI,GAAE,CAAA;;;;oDAGR;AAGK;IADL,IAAA,eAAM,EAAC,8BAA8B,CAAC;IAEpC,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;IACf,WAAA,IAAA,cAAK,EAAC,WAAW,CAAC,CAAA;;;;yDAMpB;AAGK;IADL,IAAA,YAAG,EAAC,uBAAuB,CAAC;IACL,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;;;;sDAEtC;AAGK;IADL,IAAA,aAAI,EAAC,uBAAuB,CAAC;IAE3B,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;IACf,WAAA,IAAA,aAAI,GAAE,CAAA;;;;2DASR;AAGK;IADL,IAAA,eAAM,EAAC,kCAAkC,CAAC;IAExC,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;IACf,WAAA,IAAA,cAAK,EAAC,WAAW,CAAC,CAAA;;;;wDAMpB;yBAvDU,cAAc;IAD1B,IAAA,mBAAU,EAAC,OAAO,CAAC;qCAEwB,0BAAW;GAD1C,cAAc,CAwD1B"}
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare class UserModule {
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const user_controller_1 = require("./user.controller");
|
||||
const user_service_1 = require("./user.service");
|
||||
const prisma_module_1 = require("../prisma/prisma.module");
|
||||
let UserModule = class UserModule {
|
||||
};
|
||||
exports.UserModule = UserModule;
|
||||
exports.UserModule = UserModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [prisma_module_1.PrismaModule],
|
||||
controllers: [user_controller_1.UserController],
|
||||
providers: [user_service_1.UserService],
|
||||
exports: [user_service_1.UserService],
|
||||
})
|
||||
], UserModule);
|
||||
//# sourceMappingURL=user.module.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"user.module.js","sourceRoot":"","sources":["../../src/user/user.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uDAAmD;AACnD,iDAA6C;AAC7C,2DAAuD;AAQhD,IAAM,UAAU,GAAhB,MAAM,UAAU;CAAG,CAAA;AAAb,gCAAU;qBAAV,UAAU;IANtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,WAAW,EAAE,CAAC,gCAAc,CAAC;QAC7B,SAAS,EAAE,CAAC,0BAAW,CAAC;QACxB,OAAO,EAAE,CAAC,0BAAW,CAAC;KACvB,CAAC;GACW,UAAU,CAAG"}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
export declare class UserService {
|
||||
private prisma;
|
||||
constructor(prisma: PrismaService);
|
||||
getWatchlist(userId: number): Promise<({
|
||||
product: {
|
||||
prices: ({
|
||||
source: {
|
||||
id: number;
|
||||
name: string;
|
||||
url: string;
|
||||
logo: string | null;
|
||||
lastScraped: Date | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
} & {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
sourceId: number;
|
||||
regularPrice: number;
|
||||
discountedPrice: number | null;
|
||||
discountPercentage: number | null;
|
||||
unitPrice: string | null;
|
||||
promotionType: string | null;
|
||||
promotionStart: Date | null;
|
||||
promotionEnd: Date | null;
|
||||
vatIncluded: boolean;
|
||||
lastUpdated: Date;
|
||||
productId: number;
|
||||
})[];
|
||||
} & {
|
||||
id: number;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
description: string | null;
|
||||
category: string;
|
||||
availability: boolean;
|
||||
sourceProductId: string | null;
|
||||
sourceId: number;
|
||||
};
|
||||
} & {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
})[]>;
|
||||
addToWatchlist(userId: number, productId: number): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
}>;
|
||||
removeFromWatchlist(userId: number, productId: number): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
}>;
|
||||
getNotifications(userId: number): Promise<({
|
||||
product: {
|
||||
prices: ({
|
||||
source: {
|
||||
id: number;
|
||||
name: string;
|
||||
url: string;
|
||||
logo: string | null;
|
||||
lastScraped: Date | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
} & {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
sourceId: number;
|
||||
regularPrice: number;
|
||||
discountedPrice: number | null;
|
||||
discountPercentage: number | null;
|
||||
unitPrice: string | null;
|
||||
promotionType: string | null;
|
||||
promotionStart: Date | null;
|
||||
promotionEnd: Date | null;
|
||||
vatIncluded: boolean;
|
||||
lastUpdated: Date;
|
||||
productId: number;
|
||||
})[];
|
||||
} & {
|
||||
id: number;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
description: string | null;
|
||||
category: string;
|
||||
availability: boolean;
|
||||
sourceProductId: string | null;
|
||||
sourceId: number;
|
||||
};
|
||||
} & {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
priceThreshold: number | null;
|
||||
percentThreshold: number | null;
|
||||
notifyOnAnyChange: boolean;
|
||||
isActive: boolean;
|
||||
})[]>;
|
||||
configureNotification(userId: number, data: {
|
||||
productId: number;
|
||||
priceThreshold?: number;
|
||||
percentThreshold?: number;
|
||||
notifyOnAnyChange?: boolean;
|
||||
}): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
priceThreshold: number | null;
|
||||
percentThreshold: number | null;
|
||||
notifyOnAnyChange: boolean;
|
||||
isActive: boolean;
|
||||
}>;
|
||||
removeNotification(userId: number, productId: number): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
productId: number;
|
||||
userId: number;
|
||||
priceThreshold: number | null;
|
||||
percentThreshold: number | null;
|
||||
notifyOnAnyChange: boolean;
|
||||
isActive: boolean;
|
||||
}>;
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../prisma/prisma.service");
|
||||
let UserService = class UserService {
|
||||
prisma;
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async getWatchlist(userId) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
});
|
||||
if (!user) {
|
||||
throw new common_1.NotFoundException(`User with ID ${userId} not found`);
|
||||
}
|
||||
return this.prisma.watchlistItem.findMany({
|
||||
where: { userId },
|
||||
include: {
|
||||
product: {
|
||||
include: {
|
||||
prices: {
|
||||
orderBy: { lastUpdated: 'desc' },
|
||||
take: 1,
|
||||
include: { source: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
async addToWatchlist(userId, productId) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
});
|
||||
if (!user) {
|
||||
throw new common_1.NotFoundException(`User with ID ${userId} not found`);
|
||||
}
|
||||
const product = await this.prisma.product.findUnique({
|
||||
where: { id: productId },
|
||||
});
|
||||
if (!product) {
|
||||
throw new common_1.NotFoundException(`Product with ID ${productId} not found`);
|
||||
}
|
||||
return this.prisma.watchlistItem.upsert({
|
||||
where: {
|
||||
userId_productId: {
|
||||
userId,
|
||||
productId,
|
||||
},
|
||||
},
|
||||
update: {},
|
||||
create: {
|
||||
userId,
|
||||
productId,
|
||||
},
|
||||
});
|
||||
}
|
||||
async removeFromWatchlist(userId, productId) {
|
||||
const watchlistItem = await this.prisma.watchlistItem.findUnique({
|
||||
where: {
|
||||
userId_productId: {
|
||||
userId,
|
||||
productId,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!watchlistItem) {
|
||||
throw new common_1.NotFoundException(`Watchlist item for user ${userId} and product ${productId} not found`);
|
||||
}
|
||||
return this.prisma.watchlistItem.delete({
|
||||
where: {
|
||||
userId_productId: {
|
||||
userId,
|
||||
productId,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
async getNotifications(userId) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
});
|
||||
if (!user) {
|
||||
throw new common_1.NotFoundException(`User with ID ${userId} not found`);
|
||||
}
|
||||
return this.prisma.notification.findMany({
|
||||
where: { userId },
|
||||
include: {
|
||||
product: {
|
||||
include: {
|
||||
prices: {
|
||||
orderBy: { lastUpdated: 'desc' },
|
||||
take: 1,
|
||||
include: { source: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
async configureNotification(userId, data) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
});
|
||||
if (!user) {
|
||||
throw new common_1.NotFoundException(`User with ID ${userId} not found`);
|
||||
}
|
||||
const product = await this.prisma.product.findUnique({
|
||||
where: { id: data.productId },
|
||||
});
|
||||
if (!product) {
|
||||
throw new common_1.NotFoundException(`Product with ID ${data.productId} not found`);
|
||||
}
|
||||
return this.prisma.notification.upsert({
|
||||
where: {
|
||||
userId_productId: {
|
||||
userId,
|
||||
productId: data.productId,
|
||||
},
|
||||
},
|
||||
update: {
|
||||
priceThreshold: data.priceThreshold,
|
||||
percentThreshold: data.percentThreshold,
|
||||
notifyOnAnyChange: data.notifyOnAnyChange ?? false,
|
||||
isActive: true,
|
||||
},
|
||||
create: {
|
||||
userId,
|
||||
productId: data.productId,
|
||||
priceThreshold: data.priceThreshold,
|
||||
percentThreshold: data.percentThreshold,
|
||||
notifyOnAnyChange: data.notifyOnAnyChange ?? false,
|
||||
},
|
||||
});
|
||||
}
|
||||
async removeNotification(userId, productId) {
|
||||
const notification = await this.prisma.notification.findUnique({
|
||||
where: {
|
||||
userId_productId: {
|
||||
userId,
|
||||
productId,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!notification) {
|
||||
throw new common_1.NotFoundException(`Notification for user ${userId} and product ${productId} not found`);
|
||||
}
|
||||
return this.prisma.notification.delete({
|
||||
where: {
|
||||
userId_productId: {
|
||||
userId,
|
||||
productId,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
exports.UserService = UserService;
|
||||
exports.UserService = UserService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], UserService);
|
||||
//# sourceMappingURL=user.service.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"user.service.js","sourceRoot":"","sources":["../../src/user/user.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA+D;AAC/D,6DAAyD;AAGlD,IAAM,WAAW,GAAjB,MAAM,WAAW;IACF;IAApB,YAAoB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE7C,KAAK,CAAC,YAAY,CAAC,MAAc;QAC/B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;YAC7C,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;SACtB,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,0BAAiB,CAAC,gBAAgB,MAAM,YAAY,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC;YACxC,KAAK,EAAE,EAAE,MAAM,EAAE;YACjB,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,OAAO,EAAE;wBACP,MAAM,EAAE;4BACN,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE;4BAChC,IAAI,EAAE,CAAC;4BACP,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;yBAC1B;qBACF;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,MAAc,EAAE,SAAiB;QACpD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;YAC7C,KAAK,EAAE,EAAE,EAAE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