kontas-express 1.0.7 → 1.0.8
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/dist/index.js +17 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -10,7 +10,7 @@ type ${name}Response<T> = {
|
|
10
10
|
value: T
|
11
11
|
}
|
12
12
|
|
13
|
-
export class ${name}
|
13
|
+
export class ${name} {
|
14
14
|
private collectionName = "${pluralName}"
|
15
15
|
|
16
16
|
async connect() {
|
@@ -30,7 +30,7 @@ export class ${name}Repository {
|
|
30
30
|
const result = await collection.insertOne(doc)
|
31
31
|
return {
|
32
32
|
success: true,
|
33
|
-
message: "${name}
|
33
|
+
message: "${name} created successfully",
|
34
34
|
value: { ...doc, _id: result.insertedId } as ${pluralName}
|
35
35
|
}
|
36
36
|
}
|
@@ -69,23 +69,33 @@ export class ${name}Repository {
|
|
69
69
|
|
70
70
|
return {
|
71
71
|
success: true,
|
72
|
-
message: result ? "${name}
|
72
|
+
message: result ? "${name} updated successfully" : "${name} not found",
|
73
73
|
value: result as ${pluralName} | null
|
74
74
|
}
|
75
75
|
}
|
76
76
|
|
77
|
-
async delete({ id }: ${name}Id): Promise<${name}Response
|
77
|
+
async delete({ id }: ${name}Id): Promise<${name}Response<${pluralName} | null>> {
|
78
78
|
const collection = await this.connect()
|
79
|
+
|
80
|
+
const doc = await collection.findOne({ _id: new ObjectId(id) })
|
81
|
+
if (!doc) {
|
82
|
+
return {
|
83
|
+
success: true,
|
84
|
+
message: "${name} not found",
|
85
|
+
value: null
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
79
89
|
await collection.deleteOne({ _id: new ObjectId(id) })
|
80
90
|
return {
|
81
91
|
success: true,
|
82
|
-
message: "${name}
|
83
|
-
value:
|
92
|
+
message: "${name} deleted successfully",
|
93
|
+
value: doc as ${pluralName}
|
84
94
|
}
|
85
95
|
}
|
86
96
|
}
|
87
97
|
|
88
|
-
export const ${name.toLowerCase()}
|
98
|
+
export const ${name.toLowerCase()} = new ${name}()`;
|
89
99
|
export {
|
90
100
|
generateMongoRepository
|
91
101
|
};
|