diff --git a/package-lock.json b/package-lock.json index aeece7e..135b59d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "commander": "^13.1.0", "cookie-parser": "^1.4.7", "dotenv": "^16.4.7", "ejs": "^3.1.10", @@ -433,6 +434,14 @@ "color-support": "bin.js" } }, + "node_modules/commander": { + "version": "13.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-13.1.0.tgz", + "integrity": "sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==", + "engines": { + "node": ">=18" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/package.json b/package.json index 49966b1..a7f9f34 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "express-hello-world", "version": "1.0.0", "dependencies": { + "commander": "^13.1.0", "cookie-parser": "^1.4.7", "dotenv": "^16.4.7", "ejs": "^3.1.10", @@ -17,9 +18,10 @@ "start": "node src/app.js", "start:containers": "docker compose up -d --build", "stop:containers": "docker compose down", + "cli": "node src/cli.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" -} \ No newline at end of file +} diff --git a/src/cli.js b/src/cli.js new file mode 100644 index 0000000..7eeb043 --- /dev/null +++ b/src/cli.js @@ -0,0 +1,15 @@ +const { Command } = require('commander'); +const program = new Command(); + +const createInviteCommand = require('./commands/createInvite'); + +program + .version('1.0.0') + .description('CLI for managing web app tasks'); + +program + .command('createInvite ') + .description('Create an invite') + .action(createInviteCommand); + +program.parse(process.argv); \ No newline at end of file diff --git a/src/commands/createInvite.js b/src/commands/createInvite.js new file mode 100644 index 0000000..79c027c --- /dev/null +++ b/src/commands/createInvite.js @@ -0,0 +1,7 @@ +const { exec } = require('child_process'); + +const appInviteService = require('../services/appInviteService'); + +module.exports = async function createInvite(inviterNpub) { + await appInviteService.createInvite(inviterNpub); +}; diff --git a/src/services/appInviteService.js b/src/services/appInviteService.js index e7fb2de..a0642ab 100644 --- a/src/services/appInviteService.js +++ b/src/services/appInviteService.js @@ -1,3 +1,5 @@ +const uuid = require('uuid'); + const AppInvite = require('../models/AppInvite'); const InvitedNpub = require('../models/InvitedNpub'); @@ -27,7 +29,17 @@ async function isAppInviteSpent(inviteUuid) { return false; } +async function createInvite(inviterNpub) { + await AppInvite.create({ + uuid: uuid.v7(), + inviter_npub: inviterNpub, + created_at: new Date().toISOString() + } + ); +} + exports.appInviteExists = appInviteExists; exports.getAppInvite = getAppInvite; exports.isAppInviteSpent = isAppInviteSpent; +exports.createInvite = createInvite;