X-Git-Url: http://git.squeep.com/?p=squeep-indie-auther;a=blobdiff_plain;f=bin%2FaddProfile.js;fp=bin%2FaddProfile.js;h=6a47b3c38d325b9520c48eda0223f62bb3e4a831;hp=0000000000000000000000000000000000000000;hb=b0103b0d496262c438b40bc20304081dbfe41e73;hpb=8ed81748bce7cea7904cac7225b20a60cafdfc16 diff --git a/bin/addProfile.js b/bin/addProfile.js new file mode 100644 index 0000000..6a47b3c --- /dev/null +++ b/bin/addProfile.js @@ -0,0 +1,38 @@ +'use strict'; + +const DB = require('../src/db'); +const Logger = require('../src/logger'); +const Config = require('../config'); +const config = new Config(process.env.NODE_ENV); + +const logger = new Logger(config); +const db = new DB(logger, config); + + +const identifier = process.argv[2]; +const profile = process.argv[3]; + +if (!identifier) { + console.log('missing user'); + throw new Error('missing argument'); +} +if (!profile) { + console.log('missing profile'); + throw new Error('missing argument'); +} + +(async () => { + await db.initialize(); + await db.context(async (dbCtx) => { + const user = await db.authenticationGet(dbCtx, identifier); + if (!user) { + console.log('user does not exist'); + throw new Error('invalid identifier'); + } + const profileURL = new URL(profile); // Validate and normalize + const result = await db.profileIdentifierInsert(dbCtx, profileURL.href, identifier); + console.log(result); + }); + console.log('done'); + await db._closeConnection(); +})();