Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwieds committed Mar 24, 2023
1 parent df03c1f commit 46f211a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 26 deletions.
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backend-manager",
"version": "2.5.62",
"version": "2.5.63",
"description": "Quick tools for developing Firebase functions",
"main": "src/manager/index.js",
"bin": {
Expand Down Expand Up @@ -31,7 +31,7 @@
"@google-cloud/storage": "^5.20.5",
"@sendgrid/mail": "^7.7.0",
"@sentry/node": "^6.19.7",
"backend-assistant": "^1.0.0",
"backend-assistant": "^1.0.1",
"busboy": "^1.6.0",
"chalk": "^4.1.2",
"cors": "^2.8.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const _ = require('lodash')
const powertools = require('node-powertools')

function Module() {

Expand All @@ -12,11 +13,25 @@ Module.prototype.main = function () {
const payload = self.payload;

return new Promise(async function(resolve, reject) {
const oldDate = powertools.timestamp(new Date(0), {output: 'string'})
const oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'});

self.Api.resolveUser({adminRequired: false})
.then(async (user) => {
const result = {
plan: {
id: _.get(user, 'plan.id', 'unknown'),
expires: {
timestamp: _.get(user, 'plan.expires.timestamp', oldDate),
timestampUNIX: _.get(user, 'plan.expires.timestampUNIX', oldDateUNIX),
},
trial: {
activated: _.get(user, 'plan.trial.activated', false),
date: {
timestamp: _.get(user, 'plan.trial.date.timestamp', oldDate),
timestampUNIX: _.get(user, 'plan.trial.date.timestampUNIX', oldDateUNIX),
}
},
payment: {
active: _.get(user, 'plan.payment.active', false),
},
Expand Down
38 changes: 33 additions & 5 deletions src/manager/helpers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const UIDGenerator = require('uid-generator');
const uidgen = new UIDGenerator(256);

function User(settings, options) {
let self = this;
const self = this;

settings = settings || {};
options = options || {};
let now = powertools.timestamp(new Date(), {output: 'string'});
let nowUNIX = powertools.timestamp(now, {output: 'unix'});
let oldDate = powertools.timestamp(new Date(0), {output: 'string'})
let oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'});

const now = powertools.timestamp(new Date(), {output: 'string'});
const nowUNIX = powertools.timestamp(now, {output: 'unix'});
const oldDate = powertools.timestamp(new Date(0), {output: 'string'})
const oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'});

const useDefaults = typeof options.defaults === 'undefined' ? true : options.defaults;

Expand All @@ -33,6 +35,13 @@ function User(settings, options) {
timestamp: _.get(settings, 'plan.expires.timestamp', useDefaults ? oldDate : null),
timestampUNIX: _.get(settings, 'plan.expires.timestampUNIX', useDefaults ? oldDateUNIX : null),
},
trial: {
activated: _.get(settings, 'plan.trial.activated', useDefaults ? false : null),
date: {
timestamp: _.get(settings, 'plan.trial.date.timestamp', useDefaults ? oldDate : null),
timestampUNIX: _.get(settings, 'plan.trial.date.timestampUNIX', useDefaults ? oldDateUNIX : null),
}
},
limits: {
// devices: _.get(settings, 'plan.limits.devices', null),
},
Expand Down Expand Up @@ -77,6 +86,25 @@ function User(settings, options) {
clientId: _.get(settings, 'api.clientId', useDefaults ? `${uuid4()}` : null),
privateKey: _.get(settings, 'api.privateKey', useDefaults ? `${uidgen.generateSync()}` : null),
},
personal: {
birthday: {
timestamp: _.get(settings, 'personal.birthday.timestamp', useDefaults ? oldDate : null),
timestampUNIX: _.get(settings, 'personal.birthday.timestampUNIX', useDefaults ? oldDateUNIX : null),
},
gender: _.get(settings, 'personal.gender', useDefaults ? 'undisclosed' : null),
location: {
city: _.get(settings, 'personal.location.city', useDefaults ? 'undisclosed' : null),
country: _.get(settings, 'personal.location.country', useDefaults ? 'ZZ' : null),
},
name: {
first: _.get(settings, 'personal.name.first', useDefaults ? 'undisclosed' : null),
last: _.get(settings, 'personal.name.last', useDefaults ? 'undisclosed' : null),
},
telephone: {
countryCode: _.get(settings, 'personal.telephone.countryCode', useDefaults ? 0 : null),
national: _.get(settings, 'personal.telephone.national', useDefaults ? 0 : null),
},
},
}

if (options.prune) {
Expand Down

0 comments on commit 46f211a

Please sign in to comment.