@tolinax/ayoune-cli 2024.2.14 → 2024.2.16
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/lib/commands/createAuditCommand.js +30 -28
- package/lib/commands/createCopyCommand.js +24 -24
- package/lib/commands/createCreateCommand.js +31 -29
- package/lib/commands/createDescribeCommand.js +27 -24
- package/lib/commands/createEditCommand.js +28 -25
- package/lib/commands/createGetCommand.js +36 -36
- package/lib/commands/createStorageCommand.js +16 -16
- package/lib/helpers/handleResponseFormatOptions.js +43 -43
- package/lib/operations/handleCreateSingleOperation.js +27 -27
- package/package.json +1 -1
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { Argument } from "commander";
|
|
2
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
-
import { handleAuditOperation } from "../operations/handleAuditOperation.js";
|
|
4
|
-
import { promptAudits } from "../prompts/promptAudits.js";
|
|
5
|
-
import { handleSingleAuditOperation } from "../operations/handleSingleAuditOperation.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
.addArgument(new Argument("[
|
|
11
|
-
.
|
|
12
|
-
.
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
import { Argument } from "commander";
|
|
2
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
+
import { handleAuditOperation } from "../operations/handleAuditOperation.js";
|
|
4
|
+
import { promptAudits } from "../prompts/promptAudits.js";
|
|
5
|
+
import { handleSingleAuditOperation } from "../operations/handleSingleAuditOperation.js";
|
|
6
|
+
import yaml from "js-yaml";
|
|
7
|
+
export function createAuditCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("audit")
|
|
10
|
+
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
|
|
11
|
+
.addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
|
|
12
|
+
.alias("history")
|
|
13
|
+
.description("Get the history of <id> in <collection>")
|
|
14
|
+
.action(async (collection, id, options) => {
|
|
15
|
+
try {
|
|
16
|
+
const opts = { ...program.opts(), ...options };
|
|
17
|
+
const { data, content, result, meta } = await handleAuditOperation(collection, id, {
|
|
18
|
+
...opts,
|
|
19
|
+
});
|
|
20
|
+
const selectedAudit = await promptAudits(result);
|
|
21
|
+
const { singleData, singleContent, singleResult, singleMeta } = await handleSingleAuditOperation(collection, id, selectedAudit, {
|
|
22
|
+
...opts,
|
|
23
|
+
});
|
|
24
|
+
console.log(yaml.dump(singleContent));
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error(e);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Argument } from "commander";
|
|
2
|
-
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
3
|
-
import { handleCopySingleOperation } from "../operations/handleCopySingleOperation.js";
|
|
4
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
5
|
-
export function createCopyCommand(program) {
|
|
6
|
-
program
|
|
7
|
-
.command("copy")
|
|
8
|
-
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"),
|
|
9
|
-
.addArgument(new Argument("[id]", "The id to
|
|
10
|
-
.alias("cp")
|
|
11
|
-
.description("Copy entry with <id> in <collection>")
|
|
12
|
-
.action(async (collection, id, options) => {
|
|
13
|
-
try {
|
|
14
|
-
const opts = { ...program.opts(), ...options };
|
|
15
|
-
const module = getModuleFromCollection(collection);
|
|
16
|
-
await handleCopySingleOperation(module.module, collection, id, {
|
|
17
|
-
...opts,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
console.error(e);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
1
|
+
import { Argument } from "commander";
|
|
2
|
+
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
3
|
+
import { handleCopySingleOperation } from "../operations/handleCopySingleOperation.js";
|
|
4
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
5
|
+
export function createCopyCommand(program) {
|
|
6
|
+
program
|
|
7
|
+
.command("copy")
|
|
8
|
+
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
|
|
9
|
+
.addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
|
|
10
|
+
.alias("cp")
|
|
11
|
+
.description("Copy entry with <id> in <collection>")
|
|
12
|
+
.action(async (collection, id, options) => {
|
|
13
|
+
try {
|
|
14
|
+
const opts = { ...program.opts(), ...options };
|
|
15
|
+
const module = getModuleFromCollection(collection);
|
|
16
|
+
await handleCopySingleOperation(module.module, collection, id, {
|
|
17
|
+
...opts,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.error(e);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
1
|
+
import { Argument } from "commander";
|
|
2
|
+
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
3
|
+
import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
|
|
4
|
+
import { handleCreateSingleOperation } from "../operations/handleCreateSingleOperation.js";
|
|
5
|
+
import { promptName } from "../prompts/promptName.js";
|
|
6
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
7
|
+
export function createCreateCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("create")
|
|
10
|
+
.alias("c")
|
|
11
|
+
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
|
|
12
|
+
.description("Create entry in <collection>")
|
|
13
|
+
.action(async (collection, options) => {
|
|
14
|
+
try {
|
|
15
|
+
const opts = { ...program.opts(), ...options };
|
|
16
|
+
if (!collection) {
|
|
17
|
+
collection = await promptCollectionWithModule();
|
|
18
|
+
}
|
|
19
|
+
const module = getModuleFromCollection(collection);
|
|
20
|
+
const name = await promptName();
|
|
21
|
+
await handleCreateSingleOperation(module.module, collection, name, {
|
|
22
|
+
...opts,
|
|
23
|
+
});
|
|
24
|
+
localStorage.setItem("lastModule", module.module);
|
|
25
|
+
localStorage.setItem("lastCollection", collection);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
console.error(e);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import { Argument } from "commander";
|
|
2
|
+
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
3
|
+
import { handleDescribeSingleOperation } from "../operations/handleDescribeSingleOperation.js";
|
|
4
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
5
|
+
export function createDescribeCommand(program) {
|
|
6
|
+
program
|
|
7
|
+
.command("describe")
|
|
8
|
+
.alias("d")
|
|
9
|
+
.description("Describe entry with <id> in <collection>")
|
|
10
|
+
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
|
|
11
|
+
.addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
|
|
12
|
+
.action(async (collection, id, options) => {
|
|
13
|
+
try {
|
|
14
|
+
const opts = { ...program.opts(), ...options };
|
|
15
|
+
const module = getModuleFromCollection(collection);
|
|
16
|
+
localStorage.setItem("lastModule", module.module);
|
|
17
|
+
localStorage.setItem("lastCollection", collection);
|
|
18
|
+
localStorage.setItem("lastId", id);
|
|
19
|
+
await handleDescribeSingleOperation(module.module, collection, id, {
|
|
20
|
+
...opts,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { Argument } from "commander";
|
|
2
|
+
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
3
|
+
import { handleGetSingleOperation } from "../operations/handleGetSingleOperation.js";
|
|
4
|
+
import { handleEditOperation } from "../operations/handleEditOperation.js";
|
|
5
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
6
|
+
export function createEditCommand(program) {
|
|
7
|
+
program
|
|
8
|
+
.command("edit")
|
|
9
|
+
.alias("e")
|
|
10
|
+
.description("Edit entry with [id] in [collection]")
|
|
11
|
+
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
|
|
12
|
+
.addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
|
|
13
|
+
.action(async (collection, id, options) => {
|
|
14
|
+
try {
|
|
15
|
+
const opts = { ...program.opts(), ...options };
|
|
16
|
+
const module = getModuleFromCollection(collection);
|
|
17
|
+
localStorage.setItem("lastModule", module.module);
|
|
18
|
+
localStorage.setItem("lastCollection", collection);
|
|
19
|
+
localStorage.setItem("lastId", id);
|
|
20
|
+
let result = {};
|
|
21
|
+
result = await handleGetSingleOperation(module.module, collection, id, opts);
|
|
22
|
+
await handleEditOperation(module.module, collection, result.content);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
console.error(e);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { parseInteger } from "../helpers/parseInt.js";
|
|
2
|
-
import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
|
|
3
|
-
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
4
|
-
import { saveFile } from "../helpers/saveFile.js";
|
|
5
|
-
import { handleGetOperation } from "../operations/handleGetOperation.js";
|
|
6
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
7
|
-
export function createGetCommand(program) {
|
|
8
|
-
program
|
|
9
|
-
.command("get [collection]")
|
|
10
|
-
.alias("g")
|
|
11
|
-
.description("Get Data in collection")
|
|
12
|
-
.option("-p, --page <number>", "Page", parseInteger, 1)
|
|
13
|
-
.option("-l, --limit <number>", "Limit", parseInteger, 20)
|
|
14
|
-
.option("-f, --from <date>", "From date")
|
|
15
|
-
.option("-i, --fields <fields...>", "Fields to get")
|
|
16
|
-
.action(async (collection, options) => {
|
|
17
|
-
try {
|
|
18
|
-
const opts = { ...program.opts(), ...options };
|
|
19
|
-
if (!collection) {
|
|
20
|
-
collection = await promptCollectionWithModule();
|
|
21
|
-
}
|
|
22
|
-
const module = getModuleFromCollection(collection);
|
|
23
|
-
localStorage.setItem("lastModule", module.module);
|
|
24
|
-
localStorage.setItem("lastCollection", collection);
|
|
25
|
-
let result = {};
|
|
26
|
-
let entry = "";
|
|
27
|
-
result = await handleGetOperation(module.module, collection, opts);
|
|
28
|
-
if (opts.save) {
|
|
29
|
-
await saveFile("get", opts, result);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
console.error(e);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
1
|
+
import { parseInteger } from "../helpers/parseInt.js";
|
|
2
|
+
import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
|
|
3
|
+
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
4
|
+
import { saveFile } from "../helpers/saveFile.js";
|
|
5
|
+
import { handleGetOperation } from "../operations/handleGetOperation.js";
|
|
6
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
7
|
+
export function createGetCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("get [collection]")
|
|
10
|
+
.alias("g")
|
|
11
|
+
.description("Get Data in collection")
|
|
12
|
+
.option("-p, --page <number>", "Page", parseInteger, 1)
|
|
13
|
+
.option("-l, --limit <number>", "Limit", parseInteger, 20)
|
|
14
|
+
.option("-f, --from <date>", "From date")
|
|
15
|
+
.option("-i, --fields <fields...>", "Fields to get")
|
|
16
|
+
.action(async (collection, options) => {
|
|
17
|
+
try {
|
|
18
|
+
const opts = { ...program.opts(), ...options };
|
|
19
|
+
if (!collection) {
|
|
20
|
+
collection = await promptCollectionWithModule();
|
|
21
|
+
}
|
|
22
|
+
const module = getModuleFromCollection(collection);
|
|
23
|
+
localStorage.setItem("lastModule", module.module);
|
|
24
|
+
localStorage.setItem("lastCollection", collection);
|
|
25
|
+
let result = {};
|
|
26
|
+
let entry = "";
|
|
27
|
+
result = await handleGetOperation(module.module, collection, opts);
|
|
28
|
+
if (opts.save) {
|
|
29
|
+
await saveFile("get", opts, result);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
console.error(e);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
2
|
-
export function createStorageCommand(program) {
|
|
3
|
-
program
|
|
4
|
-
.command("storage")
|
|
5
|
-
.alias("s")
|
|
6
|
-
.description("Show current local storage")
|
|
7
|
-
.action(async () => {
|
|
8
|
-
try {
|
|
9
|
-
const storage = { ...localStorage };
|
|
10
|
-
console.table(storage);
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
console.error(e);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
1
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
2
|
+
export function createStorageCommand(program) {
|
|
3
|
+
program
|
|
4
|
+
.command("storage")
|
|
5
|
+
.alias("s")
|
|
6
|
+
.description("Show current local storage")
|
|
7
|
+
.action(async () => {
|
|
8
|
+
try {
|
|
9
|
+
const storage = { ...localStorage };
|
|
10
|
+
console.table(storage);
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
console.error(e);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import yaml from "js-yaml";
|
|
2
|
-
export function handleResponseFormatOptions(opts, res) {
|
|
3
|
-
let plainResult;
|
|
4
|
-
let result;
|
|
5
|
-
let meta = {};
|
|
6
|
-
let content;
|
|
7
|
-
if (opts.responseFormat && opts.responseFormat === "yaml") {
|
|
8
|
-
plainResult = yaml.load(res);
|
|
9
|
-
result = plainResult.payload;
|
|
10
|
-
meta = plainResult.meta;
|
|
11
|
-
content = yaml.dump(result);
|
|
12
|
-
console.log("\n");
|
|
13
|
-
console.log(content);
|
|
14
|
-
console.log("\n");
|
|
15
|
-
}
|
|
16
|
-
if (opts.responseFormat && opts.responseFormat === "csv") {
|
|
17
|
-
plainResult = res;
|
|
18
|
-
result = res.payload;
|
|
19
|
-
meta = res.meta;
|
|
20
|
-
content = result;
|
|
21
|
-
console.log("\n");
|
|
22
|
-
console.log(content);
|
|
23
|
-
console.log("\n");
|
|
24
|
-
}
|
|
25
|
-
if (opts.responseFormat && opts.responseFormat === "table") {
|
|
26
|
-
plainResult = res;
|
|
27
|
-
result = res.payload;
|
|
28
|
-
meta = res.meta;
|
|
29
|
-
content = result;
|
|
30
|
-
console.log("\n");
|
|
31
|
-
console.log(res);
|
|
32
|
-
console.log("\n");
|
|
33
|
-
}
|
|
34
|
-
if (opts.responseFormat && opts.responseFormat === "json") {
|
|
35
|
-
result = res.payload;
|
|
36
|
-
meta = res.meta;
|
|
37
|
-
content = JSON.stringify(result, null, 4);
|
|
38
|
-
console.log("\n");
|
|
39
|
-
console.table(result);
|
|
40
|
-
console.log("\n");
|
|
41
|
-
}
|
|
42
|
-
return { plainResult, result, meta, content };
|
|
43
|
-
}
|
|
1
|
+
import yaml from "js-yaml";
|
|
2
|
+
export function handleResponseFormatOptions(opts, res) {
|
|
3
|
+
let plainResult;
|
|
4
|
+
let result;
|
|
5
|
+
let meta = {};
|
|
6
|
+
let content;
|
|
7
|
+
if (opts.responseFormat && opts.responseFormat === "yaml") {
|
|
8
|
+
plainResult = yaml.load(res);
|
|
9
|
+
result = plainResult.payload;
|
|
10
|
+
meta = plainResult.meta;
|
|
11
|
+
content = yaml.dump(result);
|
|
12
|
+
console.log("\n");
|
|
13
|
+
console.log(content);
|
|
14
|
+
console.log("\n");
|
|
15
|
+
}
|
|
16
|
+
if (opts.responseFormat && opts.responseFormat === "csv") {
|
|
17
|
+
plainResult = res;
|
|
18
|
+
result = res.payload;
|
|
19
|
+
meta = res.meta;
|
|
20
|
+
content = result;
|
|
21
|
+
console.log("\n");
|
|
22
|
+
console.log(content);
|
|
23
|
+
console.log("\n");
|
|
24
|
+
}
|
|
25
|
+
if (opts.responseFormat && opts.responseFormat === "table") {
|
|
26
|
+
plainResult = res;
|
|
27
|
+
result = res.payload;
|
|
28
|
+
meta = res.meta;
|
|
29
|
+
content = result;
|
|
30
|
+
console.log("\n");
|
|
31
|
+
console.log(res);
|
|
32
|
+
console.log("\n");
|
|
33
|
+
}
|
|
34
|
+
if (opts.responseFormat && opts.responseFormat === "json") {
|
|
35
|
+
result = res.payload;
|
|
36
|
+
meta = res.meta;
|
|
37
|
+
content = JSON.stringify(result, null, 4);
|
|
38
|
+
console.log("\n");
|
|
39
|
+
console.table(result);
|
|
40
|
+
console.log("\n");
|
|
41
|
+
}
|
|
42
|
+
return { plainResult, result, meta, content };
|
|
43
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
6
|
-
export async function handleCreateSingleOperation(module, collection, name, opts) {
|
|
7
|
-
spinner.start({
|
|
8
|
-
text: `Creating entry in [${collection}]`,
|
|
9
|
-
color: "magenta",
|
|
10
|
-
});
|
|
11
|
-
let res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "post", {
|
|
12
|
-
name,
|
|
13
|
-
title: name,
|
|
14
|
-
subject: name,
|
|
15
|
-
summary: name,
|
|
16
|
-
}, {
|
|
17
|
-
responseFormat: opts.responseFormat,
|
|
18
|
-
verbosity: opts.verbosity,
|
|
19
|
-
});
|
|
20
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts }, res);
|
|
21
|
-
spinner.success({
|
|
22
|
-
text: `Created entry [${result._id}] in ${collection}`,
|
|
23
|
-
});
|
|
24
|
-
spinner.stop();
|
|
25
|
-
localStorage.setItem("lastId", result._id);
|
|
26
|
-
return { data: plainResult, content, result, meta };
|
|
27
|
-
}
|
|
1
|
+
// Operation handling functions
|
|
2
|
+
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
+
import { spinner } from "../../index.js";
|
|
4
|
+
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
6
|
+
export async function handleCreateSingleOperation(module, collection, name, opts) {
|
|
7
|
+
spinner.start({
|
|
8
|
+
text: `Creating entry in [${collection}]`,
|
|
9
|
+
color: "magenta",
|
|
10
|
+
});
|
|
11
|
+
let res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "post", {
|
|
12
|
+
name,
|
|
13
|
+
title: name,
|
|
14
|
+
subject: name,
|
|
15
|
+
summary: name,
|
|
16
|
+
}, {
|
|
17
|
+
responseFormat: opts.responseFormat,
|
|
18
|
+
verbosity: opts.verbosity,
|
|
19
|
+
});
|
|
20
|
+
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts }, res);
|
|
21
|
+
spinner.success({
|
|
22
|
+
text: `Created entry [${result._id}] in ${collection}`,
|
|
23
|
+
});
|
|
24
|
+
spinner.stop();
|
|
25
|
+
localStorage.setItem("lastId", result._id);
|
|
26
|
+
return { data: plainResult, content, result, meta };
|
|
27
|
+
}
|