Skip to content

Commit

Permalink
add walletPNT and appPNT (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Pedro da Silva authored Oct 13, 2022
1 parent bb4a001 commit 58dfa07
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 8 deletions.
8 changes: 8 additions & 0 deletions packages/api/src/controllers/v2/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class UserController {
language,
currency,
pushNotificationToken,
walletPNT,
appPNT,
firstName,
lastName,
age,
Expand All @@ -40,6 +42,8 @@ class UserController {
language,
currency,
pushNotificationToken,
walletPNT,
appPNT,
firstName,
lastName,
year: age ? new Date().getUTCFullYear() - age : undefined,
Expand Down Expand Up @@ -122,6 +126,8 @@ class UserController {
language,
currency,
pushNotificationToken,
walletPNT,
appPNT,
firstName,
lastName,
age,
Expand All @@ -139,6 +145,8 @@ class UserController {
language,
currency,
pushNotificationToken,
walletPNT,
appPNT,
firstName,
lastName,
year: age ? new Date().getUTCFullYear() - age : null,
Expand Down
14 changes: 14 additions & 0 deletions packages/api/src/routes/v2/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export default (app: Router): void => {
* pushNotificationToken:
* type: string
* required: false
* walletPNT:
* type: string
* required: false
* appPNT:
* type: string
* required: false
* firstName:
* type: string
* required: false
Expand Down Expand Up @@ -125,6 +131,14 @@ export default (app: Router): void => {
* type: string
* nullable: true
* required: false
* walletPNT:
* type: string
* nullable: true
* required: false
* appPNT:
* type: string
* nullable: true
* required: false
* firstName:
* type: string
* required: false
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/validators/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const create = celebrate({
language: Joi.string().optional(),
currency: Joi.string().optional(),
pushNotificationToken: Joi.alternatives(Joi.string(), null).optional(),
walletPNT: Joi.alternatives(Joi.string(), null).optional(),
appPNT: Joi.alternatives(Joi.string(), null).optional(),
firstName: Joi.string().optional(),
lastName: Joi.string().optional(),
gender: Joi.string().optional(),
Expand All @@ -34,6 +36,8 @@ const update = celebrate({
language: Joi.alternatives(Joi.string(), null).optional(),
currency: Joi.alternatives(Joi.string(), null).optional(),
pushNotificationToken: Joi.alternatives(Joi.string(), null).optional(),
walletPNT: Joi.alternatives(Joi.string(), null).optional(),
appPNT: Joi.alternatives(Joi.string(), null).optional(),
firstName: Joi.alternatives(Joi.string(), null).optional(),
lastName: Joi.alternatives(Joi.string(), null).optional(),
gender: Joi.string().optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ module.exports = {
pushNotificationToken: {
type: Sequelize.STRING(64),
},
walletPNT: {
type: Sequelize.STRING(256),
},
appPNT: {
type: Sequelize.STRING(256),
},
gender: {
type: Sequelize.STRING(2),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

// eslint-disable-next-line no-undef
module.exports = {
async up(queryInterface, Sequelize) {
if (process.env.NODE_ENV === 'test') {
return;
}
await queryInterface.addColumn('app_user', 'walletPNT', {
type: Sequelize.STRING(256),
allowNull: true,
});

await queryInterface.addColumn('app_user', 'appPNT', {
type: Sequelize.STRING(256),
allowNull: true,
});
},

down(queryInterface, Sequelize) {},
};
8 changes: 8 additions & 0 deletions packages/core/src/database/models/app/appUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class AppUserModel extends Model<AppUser, AppUserCreationAttributes> {
public language!: string;
public currency!: string;
public pushNotificationToken!: string | null;
public walletPNT!: string | null;
public appPNT!: string | null;
public gender!: string;
public year!: number | null;
public children!: number | null;
Expand Down Expand Up @@ -81,6 +83,12 @@ export function initializeAppUser(sequelize: Sequelize): typeof AppUserModel {
pushNotificationToken: {
type: DataTypes.STRING(64),
},
walletPNT: {
type: DataTypes.STRING(256),
},
appPNT: {
type: DataTypes.STRING(256),
},
gender: {
type: DataTypes.STRING(2),
defaultValue: 'u',
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/interfaces/app/appUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { AppUserTrust, AppUserTrustCreation } from './appUserTrust';
* - language
* - currency
* - pushNotificationToken
* - walletPNT
* - appPNT
* - gender
* - year
* - children
Expand All @@ -40,6 +42,12 @@ import { AppUserTrust, AppUserTrustCreation } from './appUserTrust';
* pushNotificationToken:
* type: string
* description: User push notifications token, used in the app
* walletPNT:
* type: string
* description: User push notifications token, used in the wallet
* appPNT:
* type: string
* description: User push notifications token, used in the web app
* gender:
* type: string
* enum: [u, m, f, o]
Expand Down Expand Up @@ -82,6 +90,8 @@ export interface AppUser {
language: string;
currency: string;
pushNotificationToken: string | null;
walletPNT: string | null;
appPNT: string | null;
gender: string;
year: number | null;
children: number | null;
Expand Down Expand Up @@ -114,6 +124,8 @@ export interface AppUserUpdate {
language?: string;
currency?: string;
pushNotificationToken?: string | null;
walletPNT?: string | null;
appPNT?: string | null;
gender?: string;
year?: number | null;
children?: number | null;
Expand All @@ -137,6 +149,8 @@ export interface AppUserCreationAttributes {
avatarMediaId?: number;
avatarMediaPath?: string;
pushNotificationToken?: string;
walletPNT?: string;
appPNT?: string;
active?: boolean;
email?: string;
bio?: string;
Expand Down
21 changes: 13 additions & 8 deletions packages/core/src/services/app/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,19 @@ export default class UserService {
// including their phone number information, if it exists
user = await models.appUser.create(userParams);
} else {
if (userParams.pushNotificationToken) {
models.appUser.update(
{
pushNotificationToken: userParams.pushNotificationToken,
},
{ where: { address: userParams.address } }
);
}
const pushNotification = {
pushNotificationToken: userParams.pushNotificationToken,
walletPNT: userParams.walletPNT,
appPNT: userParams.appPNT,
};

await models.appUser.update(
{
...pushNotification,
},
{ where: { address: userParams.address } }
);

// it's not null at this point
user = (await models.appUser.findOne({
where: { address: userParams.address },
Expand Down

0 comments on commit 58dfa07

Please sign in to comment.