easyfeat 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +323 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +44 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +216 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/delete.d.ts +2 -0
- package/dist/commands/delete.d.ts.map +1 -0
- package/dist/commands/delete.js +36 -0
- package/dist/commands/delete.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/file-utils.d.ts +42 -0
- package/dist/utils/file-utils.d.ts.map +1 -0
- package/dist/utils/file-utils.js +113 -0
- package/dist/utils/file-utils.js.map +1 -0
- package/dist/utils/route-utils.d.ts +3 -0
- package/dist/utils/route-utils.d.ts.map +1 -0
- package/dist/utils/route-utils.js +139 -0
- package/dist/utils/route-utils.js.map +1 -0
- package/dist/utils/template-generator.d.ts +29 -0
- package/dist/utils/template-generator.d.ts.map +1 -0
- package/dist/utils/template-generator.js +419 -0
- package/dist/utils/template-generator.js.map +1 -0
- package/package.json +56 -0
- package/templates/base.repository.interface.ts +9 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.templates = void 0;
|
|
4
|
+
exports.templates = {
|
|
5
|
+
baseRepositoryInterface: () => `export interface IBaseRepository<T> {
|
|
6
|
+
create(data: Partial<T>): Promise<T>;
|
|
7
|
+
findById(id: string): Promise<T | null>;
|
|
8
|
+
findOne(filter: Partial<T>): Promise<T | null>;
|
|
9
|
+
findMany(filter: Partial<T>): Promise<T[]>;
|
|
10
|
+
update(id: string, data: Partial<T>): Promise<T | null>;
|
|
11
|
+
delete(id: string): Promise<boolean>;
|
|
12
|
+
exists(filter: Partial<T>): Promise<boolean>;
|
|
13
|
+
}`,
|
|
14
|
+
entity: (ctx) => `export class ${ctx.featureNamePascal} {
|
|
15
|
+
id!: string;
|
|
16
|
+
createdAt!: Date;
|
|
17
|
+
updatedAt!: Date;
|
|
18
|
+
|
|
19
|
+
constructor(data: Partial<${ctx.featureNamePascal}>) {
|
|
20
|
+
Object.assign(this, data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
toJSON() {
|
|
24
|
+
return {
|
|
25
|
+
id: this.id,
|
|
26
|
+
createdAt: this.createdAt,
|
|
27
|
+
updatedAt: this.updatedAt
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}`,
|
|
31
|
+
entityMinimal: (ctx) => `export class ${ctx.featureNamePascal} {
|
|
32
|
+
id!: string;
|
|
33
|
+
createdAt!: Date;
|
|
34
|
+
updatedAt!: Date;
|
|
35
|
+
|
|
36
|
+
constructor(data: Partial<${ctx.featureNamePascal}>) {
|
|
37
|
+
Object.assign(this, data);
|
|
38
|
+
}
|
|
39
|
+
}`,
|
|
40
|
+
repositoryInterface: (ctx) => `import { IBaseRepository } from '../../../core/interfaces/base.repository.interface';
|
|
41
|
+
import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
42
|
+
|
|
43
|
+
export interface I${ctx.featureNamePascal}Repository extends IBaseRepository<${ctx.featureNamePascal}> {
|
|
44
|
+
// Add custom repository methods here
|
|
45
|
+
}`,
|
|
46
|
+
repositoryInterfaceMinimal: (ctx) => `import { IBaseRepository } from '../../../core/interfaces/base.repository.interface';
|
|
47
|
+
import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
48
|
+
|
|
49
|
+
export interface I${ctx.featureNamePascal}Repository extends IBaseRepository<${ctx.featureNamePascal}> {}`,
|
|
50
|
+
repository: (ctx) => `import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
51
|
+
import { ${ctx.featureNamePascal}Model, I${ctx.featureNamePascal}Document } from '../models/${ctx.featureNameKebab}.model';
|
|
52
|
+
import { I${ctx.featureNamePascal}Repository } from '../interfaces/i-${ctx.featureNameKebab}.repository';
|
|
53
|
+
import { ${ctx.featureNamePascal}Mapper } from '../mappers/${ctx.featureNameKebab}.mapper';
|
|
54
|
+
import { FilterQuery } from 'mongoose';
|
|
55
|
+
|
|
56
|
+
export class ${ctx.featureNamePascal}Repository implements I${ctx.featureNamePascal}Repository {
|
|
57
|
+
async create(data: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal}> {
|
|
58
|
+
const modelData = ${ctx.featureNamePascal}Mapper.toModel(data);
|
|
59
|
+
const created = await ${ctx.featureNamePascal}Model.create(modelData);
|
|
60
|
+
return ${ctx.featureNamePascal}Mapper.toEntity(created);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async findById(id: string): Promise<${ctx.featureNamePascal} | null> {
|
|
64
|
+
const found = await ${ctx.featureNamePascal}Model.findById(id);
|
|
65
|
+
return found ? ${ctx.featureNamePascal}Mapper.toEntity(found) : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async findOne(filter: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal} | null> {
|
|
69
|
+
const modelFilter = ${ctx.featureNamePascal}Mapper.toModel(filter) as FilterQuery<I${ctx.featureNamePascal}Document>;
|
|
70
|
+
const found = await ${ctx.featureNamePascal}Model.findOne(modelFilter);
|
|
71
|
+
return found ? ${ctx.featureNamePascal}Mapper.toEntity(found) : null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async findMany(filter: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal}[]> {
|
|
75
|
+
const modelFilter = ${ctx.featureNamePascal}Mapper.toModel(filter) as FilterQuery<I${ctx.featureNamePascal}Document>;
|
|
76
|
+
const found = await ${ctx.featureNamePascal}Model.find(modelFilter);
|
|
77
|
+
return ${ctx.featureNamePascal}Mapper.toEntities(found);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async update(id: string, data: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal} | null> {
|
|
81
|
+
const modelData = ${ctx.featureNamePascal}Mapper.toModel(data);
|
|
82
|
+
const updated = await ${ctx.featureNamePascal}Model.findByIdAndUpdate(id, modelData, { new: true });
|
|
83
|
+
return updated ? ${ctx.featureNamePascal}Mapper.toEntity(updated) : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async delete(id: string): Promise<boolean> {
|
|
87
|
+
const result = await ${ctx.featureNamePascal}Model.findByIdAndDelete(id);
|
|
88
|
+
return !!result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async exists(filter: Partial<${ctx.featureNamePascal}>): Promise<boolean> {
|
|
92
|
+
const modelFilter = ${ctx.featureNamePascal}Mapper.toModel(filter) as FilterQuery<I${ctx.featureNamePascal}Document>;
|
|
93
|
+
const result = await ${ctx.featureNamePascal}Model.exists(modelFilter);
|
|
94
|
+
return !!result;
|
|
95
|
+
}
|
|
96
|
+
}`,
|
|
97
|
+
repositoryMinimal: (ctx) => `import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
98
|
+
import { ${ctx.featureNamePascal}Model } from '../models/${ctx.featureNameKebab}.model';
|
|
99
|
+
import { I${ctx.featureNamePascal}Repository } from '../interfaces/i-${ctx.featureNameKebab}.repository';
|
|
100
|
+
|
|
101
|
+
export class ${ctx.featureNamePascal}Repository implements I${ctx.featureNamePascal}Repository {
|
|
102
|
+
async create(data: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal}> {
|
|
103
|
+
throw new Error('Method not implemented.');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async findById(id: string): Promise<${ctx.featureNamePascal} | null> {
|
|
107
|
+
throw new Error('Method not implemented.');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async findOne(filter: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal} | null> {
|
|
111
|
+
throw new Error('Method not implemented.');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async findMany(filter: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal}[]> {
|
|
115
|
+
throw new Error('Method not implemented.');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async update(id: string, data: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal} | null> {
|
|
119
|
+
throw new Error('Method not implemented.');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async delete(id: string): Promise<boolean> {
|
|
123
|
+
throw new Error('Method not implemented.');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async exists(filter: Partial<${ctx.featureNamePascal}>): Promise<boolean> {
|
|
127
|
+
throw new Error('Method not implemented.');
|
|
128
|
+
}
|
|
129
|
+
}`,
|
|
130
|
+
mapper: (ctx) => `import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
131
|
+
import { I${ctx.featureNamePascal}Document } from '../models/${ctx.featureNameKebab}.model';
|
|
132
|
+
|
|
133
|
+
export class ${ctx.featureNamePascal}Mapper {
|
|
134
|
+
static toEntity(doc: I${ctx.featureNamePascal}Document): ${ctx.featureNamePascal} {
|
|
135
|
+
return new ${ctx.featureNamePascal}({
|
|
136
|
+
id: doc._id.toString(),
|
|
137
|
+
createdAt: doc.createdAt,
|
|
138
|
+
updatedAt: doc.updatedAt,
|
|
139
|
+
// Add other fields here
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static toModel(entity: Partial<${ctx.featureNamePascal}>): Partial<I${ctx.featureNamePascal}Document> {
|
|
144
|
+
const model: any = { ...entity };
|
|
145
|
+
if (entity.id) {
|
|
146
|
+
model._id = entity.id;
|
|
147
|
+
delete model.id;
|
|
148
|
+
}
|
|
149
|
+
return model;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
static toEntities(docs: I${ctx.featureNamePascal}Document[]): ${ctx.featureNamePascal}[] {
|
|
153
|
+
return docs.map(doc => this.toEntity(doc));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static toModels(entities: Partial<${ctx.featureNamePascal}>[]): Partial<I${ctx.featureNamePascal}Document>[] {
|
|
157
|
+
return entities.map(entity => this.toModel(entity));
|
|
158
|
+
}
|
|
159
|
+
}`,
|
|
160
|
+
validation: (ctx) => `import Joi from 'joi';
|
|
161
|
+
import { JoiAuthBearer, JoiObjectId } from '../../../helpers/validator';
|
|
162
|
+
|
|
163
|
+
export class ${ctx.featureNamePascal}Validation {
|
|
164
|
+
static create = Joi.object({
|
|
165
|
+
// Add validation for create fields
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
static update = Joi.object({
|
|
169
|
+
// Add validation for update fields
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
static id = Joi.object({
|
|
173
|
+
id: JoiObjectId().required(),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
static auth = Joi.object({
|
|
177
|
+
authorization: JoiAuthBearer().required(),
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
static query = Joi.object({
|
|
181
|
+
page: Joi.number().optional(),
|
|
182
|
+
limit: Joi.number().optional(),
|
|
183
|
+
// Add other query params
|
|
184
|
+
});
|
|
185
|
+
}`,
|
|
186
|
+
createDto: (ctx) => `import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
187
|
+
|
|
188
|
+
export class Create${ctx.featureNamePascal}DTO implements Partial<${ctx.featureNamePascal}> {
|
|
189
|
+
// Add your DTO properties here
|
|
190
|
+
|
|
191
|
+
constructor(data: Partial<Create${ctx.featureNamePascal}DTO>) {
|
|
192
|
+
Object.assign(this, data);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
validate(): void {
|
|
196
|
+
// Add validation logic here
|
|
197
|
+
}
|
|
198
|
+
}`,
|
|
199
|
+
updateDto: (ctx) => `import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
200
|
+
|
|
201
|
+
export class Update${ctx.featureNamePascal}DTO implements Partial<${ctx.featureNamePascal}> {
|
|
202
|
+
// Add your DTO properties here
|
|
203
|
+
|
|
204
|
+
constructor(data: Partial<Update${ctx.featureNamePascal}DTO>) {
|
|
205
|
+
Object.assign(this, data);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
validate(): void {
|
|
209
|
+
// Add validation logic here
|
|
210
|
+
}
|
|
211
|
+
}`,
|
|
212
|
+
model: (ctx) => `import mongoose, { Schema, Document } from 'mongoose';
|
|
213
|
+
import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
214
|
+
|
|
215
|
+
export interface I${ctx.featureNamePascal}Document extends Omit<${ctx.featureNamePascal}, 'toJSON' | 'toObject' | 'id'>, Document {
|
|
216
|
+
_id: mongoose.Types.ObjectId;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const ${ctx.featureNamePascal}Schema = new Schema<I${ctx.featureNamePascal}Document>({
|
|
220
|
+
// Add your schema fields here
|
|
221
|
+
}, {
|
|
222
|
+
timestamps: true,
|
|
223
|
+
toJSON: {
|
|
224
|
+
transform: (_, ret) => {
|
|
225
|
+
ret.id = ret._id;
|
|
226
|
+
delete ret._id;
|
|
227
|
+
delete ret.__v;
|
|
228
|
+
return ret;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
export const ${ctx.featureNamePascal}Model = mongoose.model<I${ctx.featureNamePascal}Document>('${ctx.featureNamePascal}', ${ctx.featureNamePascal}Schema);`,
|
|
234
|
+
modelMinimal: (ctx) => `import mongoose, { Schema, Document } from 'mongoose';
|
|
235
|
+
import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
236
|
+
|
|
237
|
+
export interface I${ctx.featureNamePascal}Document extends Omit<${ctx.featureNamePascal}, 'toJSON' | 'toObject' | 'id'>, Document {
|
|
238
|
+
_id: mongoose.Types.ObjectId;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const ${ctx.featureNamePascal}Schema = new Schema({
|
|
242
|
+
// Add your schema fields here
|
|
243
|
+
}, { timestamps: true });
|
|
244
|
+
|
|
245
|
+
export const ${ctx.featureNamePascal}Model = mongoose.model<I${ctx.featureNamePascal}Document>('${ctx.featureNamePascal}', ${ctx.featureNamePascal}Schema);`,
|
|
246
|
+
serviceInterface: (ctx) => `import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
247
|
+
import { Create${ctx.featureNamePascal}DTO } from '../dtos/create-${ctx.featureNameKebab}.dto';
|
|
248
|
+
import { Update${ctx.featureNamePascal}DTO } from '../dtos/update-${ctx.featureNameKebab}.dto';
|
|
249
|
+
|
|
250
|
+
export interface I${ctx.featureNamePascal}Service {
|
|
251
|
+
create(data: Create${ctx.featureNamePascal}DTO): Promise<${ctx.featureNamePascal}>;
|
|
252
|
+
findById(id: string): Promise<${ctx.featureNamePascal} | null>;
|
|
253
|
+
update(id: string, data: Update${ctx.featureNamePascal}DTO): Promise<${ctx.featureNamePascal} | null>;
|
|
254
|
+
delete(id: string): Promise<boolean>;
|
|
255
|
+
list(filter?: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal}[]>;
|
|
256
|
+
}`,
|
|
257
|
+
serviceInterfaceMinimal: (ctx) => `import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
258
|
+
|
|
259
|
+
export interface I${ctx.featureNamePascal}Service {
|
|
260
|
+
// Add your service methods here
|
|
261
|
+
}`,
|
|
262
|
+
service: (ctx) => `import { I${ctx.featureNamePascal}Service } from '../interfaces/i-${ctx.featureNameKebab}.service';
|
|
263
|
+
import { I${ctx.featureNamePascal}Repository } from '../interfaces/i-${ctx.featureNameKebab}.repository';
|
|
264
|
+
import { ${ctx.featureNamePascal}Repository } from '../repositories/${ctx.featureNameKebab}.repository';
|
|
265
|
+
import { Create${ctx.featureNamePascal}DTO } from '../dtos/create-${ctx.featureNameKebab}.dto';
|
|
266
|
+
import { Update${ctx.featureNamePascal}DTO } from '../dtos/update-${ctx.featureNameKebab}.dto';
|
|
267
|
+
import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
268
|
+
|
|
269
|
+
export class ${ctx.featureNamePascal}Service implements I${ctx.featureNamePascal}Service {
|
|
270
|
+
private repository: I${ctx.featureNamePascal}Repository;
|
|
271
|
+
|
|
272
|
+
constructor() {
|
|
273
|
+
this.repository = new ${ctx.featureNamePascal}Repository();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async create(data: Create${ctx.featureNamePascal}DTO): Promise<${ctx.featureNamePascal}> {
|
|
277
|
+
data.validate();
|
|
278
|
+
return this.repository.create(data);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async findById(id: string): Promise<${ctx.featureNamePascal} | null> {
|
|
282
|
+
return this.repository.findById(id);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async update(id: string, data: Update${ctx.featureNamePascal}DTO): Promise<${ctx.featureNamePascal} | null> {
|
|
286
|
+
data.validate();
|
|
287
|
+
return this.repository.update(id, data);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async delete(id: string): Promise<boolean> {
|
|
291
|
+
return this.repository.delete(id);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async list(filter?: Partial<${ctx.featureNamePascal}>): Promise<${ctx.featureNamePascal}[]> {
|
|
295
|
+
return this.repository.findMany(filter || {});
|
|
296
|
+
}
|
|
297
|
+
}`,
|
|
298
|
+
serviceMinimal: (ctx) => `import { I${ctx.featureNamePascal}Service } from '../interfaces/i-${ctx.featureNameKebab}.service';
|
|
299
|
+
import { ${ctx.featureNamePascal} } from '../entities/${ctx.featureNameKebab}.entity';
|
|
300
|
+
import { I${ctx.featureNamePascal}Repository } from '../interfaces/i-${ctx.featureNameKebab}.repository';
|
|
301
|
+
import { ${ctx.featureNamePascal}Repository } from '../repositories/${ctx.featureNameKebab}.repository';
|
|
302
|
+
|
|
303
|
+
export class ${ctx.featureNamePascal}Service implements I${ctx.featureNamePascal}Service {
|
|
304
|
+
private repository: I${ctx.featureNamePascal}Repository;
|
|
305
|
+
|
|
306
|
+
constructor() {
|
|
307
|
+
this.repository = new ${ctx.featureNamePascal}Repository();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Add your service methods here
|
|
311
|
+
}`,
|
|
312
|
+
controller: (ctx) => `import { Request, Response } from 'express';
|
|
313
|
+
import asyncHandler from '../../../helpers/asyncHandler';
|
|
314
|
+
import validator, { ValidationSource } from '../../../helpers/validator';
|
|
315
|
+
import { ${ctx.featureNamePascal}Service } from '../services/${ctx.featureNameKebab}.service';
|
|
316
|
+
import { Create${ctx.featureNamePascal}DTO } from '../dtos/create-${ctx.featureNameKebab}.dto';
|
|
317
|
+
import { Update${ctx.featureNamePascal}DTO } from '../dtos/update-${ctx.featureNameKebab}.dto';
|
|
318
|
+
import { ${ctx.featureNamePascal}Validation } from '../validations/${ctx.featureNameKebab}.validation';
|
|
319
|
+
|
|
320
|
+
export class ${ctx.featureNamePascal}Controller {
|
|
321
|
+
private service: ${ctx.featureNamePascal}Service;
|
|
322
|
+
|
|
323
|
+
constructor() {
|
|
324
|
+
this.service = new ${ctx.featureNamePascal}Service();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
create = [
|
|
328
|
+
validator(${ctx.featureNamePascal}Validation.auth, ValidationSource.HEADER),
|
|
329
|
+
validator(${ctx.featureNamePascal}Validation.create),
|
|
330
|
+
asyncHandler(async (req: Request, res: Response) => {
|
|
331
|
+
const data = new Create${ctx.featureNamePascal}DTO(req.body);
|
|
332
|
+
const result = await this.service.create(data);
|
|
333
|
+
res.status(201).json(result);
|
|
334
|
+
})
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
findById = [
|
|
338
|
+
validator(${ctx.featureNamePascal}Validation.auth, ValidationSource.HEADER),
|
|
339
|
+
validator(${ctx.featureNamePascal}Validation.id, ValidationSource.PARAM),
|
|
340
|
+
asyncHandler(async (req: Request, res: Response) => {
|
|
341
|
+
const { id } = req.params;
|
|
342
|
+
const result = await this.service.findById(id);
|
|
343
|
+
if (!result) {
|
|
344
|
+
return res.status(404).json({ error: '${ctx.featureNamePascal} not found' });
|
|
345
|
+
}
|
|
346
|
+
res.json(result);
|
|
347
|
+
})
|
|
348
|
+
];
|
|
349
|
+
|
|
350
|
+
update = [
|
|
351
|
+
validator(${ctx.featureNamePascal}Validation.auth, ValidationSource.HEADER),
|
|
352
|
+
validator(${ctx.featureNamePascal}Validation.id, ValidationSource.PARAM),
|
|
353
|
+
validator(${ctx.featureNamePascal}Validation.update),
|
|
354
|
+
asyncHandler(async (req: Request, res: Response) => {
|
|
355
|
+
const { id } = req.params;
|
|
356
|
+
const data = new Update${ctx.featureNamePascal}DTO(req.body);
|
|
357
|
+
const result = await this.service.update(id, data);
|
|
358
|
+
if (!result) {
|
|
359
|
+
return res.status(404).json({ error: '${ctx.featureNamePascal} not found' });
|
|
360
|
+
}
|
|
361
|
+
res.json(result);
|
|
362
|
+
})
|
|
363
|
+
];
|
|
364
|
+
|
|
365
|
+
delete = [
|
|
366
|
+
validator(${ctx.featureNamePascal}Validation.auth, ValidationSource.HEADER),
|
|
367
|
+
validator(${ctx.featureNamePascal}Validation.id, ValidationSource.PARAM),
|
|
368
|
+
asyncHandler(async (req: Request, res: Response) => {
|
|
369
|
+
const { id } = req.params;
|
|
370
|
+
const result = await this.service.delete(id);
|
|
371
|
+
if (!result) {
|
|
372
|
+
return res.status(404).json({ error: '${ctx.featureNamePascal} not found' });
|
|
373
|
+
}
|
|
374
|
+
res.status(204).send();
|
|
375
|
+
})
|
|
376
|
+
];
|
|
377
|
+
|
|
378
|
+
list = [
|
|
379
|
+
validator(${ctx.featureNamePascal}Validation.auth, ValidationSource.HEADER),
|
|
380
|
+
validator(${ctx.featureNamePascal}Validation.query, ValidationSource.QUERY),
|
|
381
|
+
asyncHandler(async (req: Request, res: Response) => {
|
|
382
|
+
const filter = req.query;
|
|
383
|
+
const results = await this.service.list(filter);
|
|
384
|
+
res.json(results);
|
|
385
|
+
})
|
|
386
|
+
];
|
|
387
|
+
}`,
|
|
388
|
+
controllerMinimal: (ctx) => `import { Request, Response } from 'express';
|
|
389
|
+
import { ${ctx.featureNamePascal}Service } from '../services/${ctx.featureNameKebab}.service';
|
|
390
|
+
|
|
391
|
+
export class ${ctx.featureNamePascal}Controller {
|
|
392
|
+
private service: ${ctx.featureNamePascal}Service;
|
|
393
|
+
|
|
394
|
+
constructor() {
|
|
395
|
+
this.service = new ${ctx.featureNamePascal}Service();
|
|
396
|
+
}
|
|
397
|
+
}`,
|
|
398
|
+
routes: (ctx) => `import { Router } from 'express';
|
|
399
|
+
import { ${ctx.featureNamePascal}Controller } from '../controllers/${ctx.featureNameKebab}.controller';
|
|
400
|
+
|
|
401
|
+
const router = Router();
|
|
402
|
+
const controller = new ${ctx.featureNamePascal}Controller();
|
|
403
|
+
|
|
404
|
+
router.post('/', controller.create);
|
|
405
|
+
router.get('/:id', controller.findById);
|
|
406
|
+
router.put('/:id', controller.update);
|
|
407
|
+
router.delete('/:id', controller.delete);
|
|
408
|
+
router.get('/', controller.list);
|
|
409
|
+
|
|
410
|
+
export default router;`,
|
|
411
|
+
routesMinimal: (ctx) => `import { Router } from 'express';
|
|
412
|
+
import { ${ctx.featureNamePascal}Controller } from '../controllers/${ctx.featureNameKebab}.controller';
|
|
413
|
+
|
|
414
|
+
const router = Router();
|
|
415
|
+
const controller = new ${ctx.featureNamePascal}Controller();
|
|
416
|
+
|
|
417
|
+
export default router;`,
|
|
418
|
+
};
|
|
419
|
+
//# sourceMappingURL=template-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-generator.js","sourceRoot":"","sources":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
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A CLI tool to quickly scaffold clean code features with repository pattern, services, controllers, and more",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"easyfeat": "dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"dev": "tsc --watch",
|
|
12
|
+
"clean": "rm -rf dist",
|
|
13
|
+
"rebuild": "npm run clean && npm run build",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"cli",
|
|
19
|
+
"scaffold",
|
|
20
|
+
"generator",
|
|
21
|
+
"feature",
|
|
22
|
+
"clean-code",
|
|
23
|
+
"repository-pattern",
|
|
24
|
+
"typescript",
|
|
25
|
+
"nodejs",
|
|
26
|
+
"backend",
|
|
27
|
+
"express"
|
|
28
|
+
],
|
|
29
|
+
"author": "Nitesh",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/yourusername/easyfeat.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/yourusername/easyfeat/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/yourusername/easyfeat#readme",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"templates",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=14.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^20.10.0",
|
|
50
|
+
"typescript": "^5.3.3"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"commander": "^11.1.0",
|
|
54
|
+
"chalk": "^4.1.2"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface IBaseRepository<T> {
|
|
2
|
+
create(data: Partial<T>): Promise<T>;
|
|
3
|
+
findById(id: string): Promise<T | null>;
|
|
4
|
+
findOne(filter: Partial<T>): Promise<T | null>;
|
|
5
|
+
findMany(filter: Partial<T>): Promise<T[]>;
|
|
6
|
+
update(id: string, data: Partial<T>): Promise<T | null>;
|
|
7
|
+
delete(id: string): Promise<boolean>;
|
|
8
|
+
exists(filter: Partial<T>): Promise<boolean>;
|
|
9
|
+
}
|