first commit
This commit is contained in:
28
apps/api/dist/categories/categories.controller.d.ts
vendored
Normal file
28
apps/api/dist/categories/categories.controller.d.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { CategoriesService } from '../categories/categories.service';
|
||||
import { CreateCategoryDto } from '../categories/dto/create-category.dto';
|
||||
export declare class CategoriesController {
|
||||
private readonly categoriesService;
|
||||
constructor(categoriesService: CategoriesService);
|
||||
private userId;
|
||||
create(createCategoryDto: CreateCategoryDto): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
name: string;
|
||||
userId: string;
|
||||
}>;
|
||||
findAll(): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
name: string;
|
||||
userId: string;
|
||||
}[]>;
|
||||
remove(id: string): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
name: string;
|
||||
userId: string;
|
||||
}>;
|
||||
}
|
||||
66
apps/api/dist/categories/categories.controller.js
vendored
Normal file
66
apps/api/dist/categories/categories.controller.js
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
"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.CategoriesController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const categories_service_1 = require("../categories/categories.service");
|
||||
const create_category_dto_1 = require("../categories/dto/create-category.dto");
|
||||
const user_util_1 = require("../common/user.util");
|
||||
let CategoriesController = class CategoriesController {
|
||||
categoriesService;
|
||||
constructor(categoriesService) {
|
||||
this.categoriesService = categoriesService;
|
||||
}
|
||||
userId() {
|
||||
return (0, user_util_1.getTempUserId)();
|
||||
}
|
||||
create(createCategoryDto) {
|
||||
return this.categoriesService.create({
|
||||
...createCategoryDto,
|
||||
userId: this.userId(),
|
||||
});
|
||||
}
|
||||
findAll() {
|
||||
return this.categoriesService.findAll(this.userId());
|
||||
}
|
||||
remove(id) {
|
||||
return this.categoriesService.remove(id, this.userId());
|
||||
}
|
||||
};
|
||||
exports.CategoriesController = CategoriesController;
|
||||
__decorate([
|
||||
(0, common_1.Post)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [create_category_dto_1.CreateCategoryDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CategoriesController.prototype, "create", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CategoriesController.prototype, "findAll", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(':id'),
|
||||
__param(0, (0, common_1.Param)('id')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CategoriesController.prototype, "remove", null);
|
||||
exports.CategoriesController = CategoriesController = __decorate([
|
||||
(0, common_1.Controller)('categories'),
|
||||
__metadata("design:paramtypes", [categories_service_1.CategoriesService])
|
||||
], CategoriesController);
|
||||
//# sourceMappingURL=categories.controller.js.map
|
||||
1
apps/api/dist/categories/categories.controller.js.map
vendored
Normal file
1
apps/api/dist/categories/categories.controller.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"categories.controller.js","sourceRoot":"","sources":["../../src/categories/categories.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,yEAAqE;AACrE,+EAA0E;AAC1E,mDAAoD;AAG7C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACF;IAA7B,YAA6B,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAE7D,MAAM;QACZ,OAAO,IAAA,yBAAa,GAAE,CAAC;IACzB,CAAC;IAGD,MAAM,CAAS,iBAAoC;QACjD,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC;YACnC,GAAG,iBAAiB;YACpB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;SACtB,CAAC,CAAC;IACL,CAAC;IAGD,OAAO;QACL,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC;IAGD,MAAM,CAAc,EAAU;QAC5B,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAxBY,oDAAoB;AAQ/B;IADC,IAAA,aAAI,GAAE;IACC,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAoB,uCAAiB;;kDAKlD;AAGD;IADC,IAAA,YAAG,GAAE;;;;mDAGL;AAGD;IADC,IAAA,eAAM,EAAC,KAAK,CAAC;IACN,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;kDAElB;+BAvBU,oBAAoB;IADhC,IAAA,mBAAU,EAAC,YAAY,CAAC;qCAEyB,sCAAiB;GADtD,oBAAoB,CAwBhC"}
|
||||
2
apps/api/dist/categories/categories.module.d.ts
vendored
Normal file
2
apps/api/dist/categories/categories.module.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare class CategoriesModule {
|
||||
}
|
||||
26
apps/api/dist/categories/categories.module.js
vendored
Normal file
26
apps/api/dist/categories/categories.module.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"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.CategoriesModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const categories_service_1 = require("./categories.service");
|
||||
const categories_controller_1 = require("./categories.controller");
|
||||
const prisma_module_1 = require("../prisma/prisma.module");
|
||||
const auth_module_1 = require("../auth/auth.module");
|
||||
let CategoriesModule = class CategoriesModule {
|
||||
};
|
||||
exports.CategoriesModule = CategoriesModule;
|
||||
exports.CategoriesModule = CategoriesModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [prisma_module_1.PrismaModule, auth_module_1.AuthModule],
|
||||
controllers: [categories_controller_1.CategoriesController],
|
||||
providers: [categories_service_1.CategoriesService],
|
||||
exports: [categories_service_1.CategoriesService],
|
||||
})
|
||||
], CategoriesModule);
|
||||
//# sourceMappingURL=categories.module.js.map
|
||||
1
apps/api/dist/categories/categories.module.js.map
vendored
Normal file
1
apps/api/dist/categories/categories.module.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"categories.module.js","sourceRoot":"","sources":["../../src/categories/categories.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,6DAAyD;AACzD,mEAA+D;AAC/D,2DAAuD;AACvD,qDAAiD;AAQ1C,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAN5B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,EAAE,wBAAU,CAAC;QACnC,WAAW,EAAE,CAAC,4CAAoB,CAAC;QACnC,SAAS,EAAE,CAAC,sCAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,sCAAiB,CAAC;KAC7B,CAAC;GACW,gBAAgB,CAAG"}
|
||||
30
apps/api/dist/categories/categories.service.d.ts
vendored
Normal file
30
apps/api/dist/categories/categories.service.d.ts
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CreateCategoryDto } from './dto/create-category.dto';
|
||||
export declare class CategoriesService {
|
||||
private prisma;
|
||||
constructor(prisma: PrismaService);
|
||||
create(data: CreateCategoryDto & {
|
||||
userId: string;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
name: string;
|
||||
userId: string;
|
||||
}>;
|
||||
findAll(userId: string): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
name: string;
|
||||
userId: string;
|
||||
}[]>;
|
||||
remove(id: string, userId: string): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
name: string;
|
||||
userId: string;
|
||||
}>;
|
||||
findOrCreate(names: string[], userId: string): Promise<any[]>;
|
||||
}
|
||||
74
apps/api/dist/categories/categories.service.js
vendored
Normal file
74
apps/api/dist/categories/categories.service.js
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
"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.CategoriesService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../prisma/prisma.service");
|
||||
let CategoriesService = class CategoriesService {
|
||||
prisma;
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async create(data) {
|
||||
try {
|
||||
return await this.prisma.category.create({
|
||||
data: {
|
||||
name: data.name,
|
||||
userId: data.userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
if (error.code === 'P2002') {
|
||||
throw new common_1.ConflictException('Category already exists');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async findAll(userId) {
|
||||
return this.prisma.category.findMany({
|
||||
where: { userId },
|
||||
orderBy: { name: 'asc' },
|
||||
});
|
||||
}
|
||||
async remove(id, userId) {
|
||||
const category = await this.prisma.category.findFirst({
|
||||
where: { id, userId },
|
||||
});
|
||||
if (!category) {
|
||||
throw new common_1.NotFoundException('Category not found');
|
||||
}
|
||||
return this.prisma.category.delete({
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
async findOrCreate(names, userId) {
|
||||
const categories = [];
|
||||
for (const name of names) {
|
||||
let category = await this.prisma.category.findFirst({
|
||||
where: { name, userId },
|
||||
});
|
||||
if (!category) {
|
||||
category = await this.prisma.category.create({
|
||||
data: { name, userId },
|
||||
});
|
||||
}
|
||||
categories.push(category);
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
};
|
||||
exports.CategoriesService = CategoriesService;
|
||||
exports.CategoriesService = CategoriesService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], CategoriesService);
|
||||
//# sourceMappingURL=categories.service.js.map
|
||||
1
apps/api/dist/categories/categories.service.js.map
vendored
Normal file
1
apps/api/dist/categories/categories.service.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"categories.service.js","sourceRoot":"","sources":["../../src/categories/categories.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAkF;AAClF,6DAAyD;AAIlD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACR;IAApB,YAAoB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE7C,KAAK,CAAC,MAAM,CAAC,IAA4C;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;gBACvC,IAAI,EAAE;oBACJ,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC3B,MAAM,IAAI,0BAAiB,CAAC,yBAAyB,CAAC,CAAC;YACzD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACnC,KAAK,EAAE,EAAE,MAAM,EAAE;YACjB,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;SACzB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,MAAc;QACrC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;YACpD,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;SACtB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,0BAAiB,CAAC,oBAAoB,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YACjC,KAAK,EAAE,EAAE,EAAE,EAAE;SACd,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAe,EAAE,MAAc;QAChD,MAAM,UAAU,GAAU,EAAE,CAAC;QAE7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAClD,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;aACxB,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;oBAC3C,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;iBACvB,CAAC,CAAC;YACL,CAAC;YAED,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF,CAAA;AA3DY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAEiB,8BAAa;GAD9B,iBAAiB,CA2D7B"}
|
||||
3
apps/api/dist/categories/dto/create-category.dto.d.ts
vendored
Normal file
3
apps/api/dist/categories/dto/create-category.dto.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export declare class CreateCategoryDto {
|
||||
name: string;
|
||||
}
|
||||
24
apps/api/dist/categories/dto/create-category.dto.js
vendored
Normal file
24
apps/api/dist/categories/dto/create-category.dto.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"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.CreateCategoryDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
class CreateCategoryDto {
|
||||
name;
|
||||
}
|
||||
exports.CreateCategoryDto = CreateCategoryDto;
|
||||
__decorate([
|
||||
(0, class_validator_1.IsString)(),
|
||||
(0, class_validator_1.IsNotEmpty)(),
|
||||
(0, class_validator_1.MaxLength)(50),
|
||||
__metadata("design:type", String)
|
||||
], CreateCategoryDto.prototype, "name", void 0);
|
||||
//# sourceMappingURL=create-category.dto.js.map
|
||||
1
apps/api/dist/categories/dto/create-category.dto.js.map
vendored
Normal file
1
apps/api/dist/categories/dto/create-category.dto.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"create-category.dto.js","sourceRoot":"","sources":["../../../src/categories/dto/create-category.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAkE;AAElE,MAAa,iBAAiB;IAI5B,IAAI,CAAS;CACd;AALD,8CAKC;AADC;IAHC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,EAAC,EAAE,CAAC;;+CACD"}
|
||||
Reference in New Issue
Block a user