initial commit
[squeep-indie-auther] / bin / addProfile.js
1 'use strict';
2
3 const DB = require('../src/db');
4 const Logger = require('../src/logger');
5 const Config = require('../config');
6 const config = new Config(process.env.NODE_ENV);
7
8 const logger = new Logger(config);
9 const db = new DB(logger, config);
10
11
12 const identifier = process.argv[2];
13 const profile = process.argv[3];
14
15 if (!identifier) {
16 console.log('missing user');
17 throw new Error('missing argument');
18 }
19 if (!profile) {
20 console.log('missing profile');
21 throw new Error('missing argument');
22 }
23
24 (async () => {
25 await db.initialize();
26 await db.context(async (dbCtx) => {
27 const user = await db.authenticationGet(dbCtx, identifier);
28 if (!user) {
29 console.log('user does not exist');
30 throw new Error('invalid identifier');
31 }
32 const profileURL = new URL(profile); // Validate and normalize
33 const result = await db.profileIdentifierInsert(dbCtx, profileURL.href, identifier);
34 console.log(result);
35 });
36 console.log('done');
37 await db._closeConnection();
38 })();