Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user country #261

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/api/src/controllers/v2/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class UserController {
email,
gender,
bio,
country,
} = req.body;
this.userService
.update({
Expand All @@ -127,6 +128,7 @@ class UserController {
email,
gender,
bio,
country,
})
.then((user) =>
standardResponse(res, 200, true, {
Expand Down
6 changes: 6 additions & 0 deletions packages/api/src/routes/v2/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export default (app: Router): void => {
* bio:
* type: string
* required: false
* country:
* type: string
* required: false
* responses:
* "200":
* description: "Success"
Expand Down Expand Up @@ -145,6 +148,9 @@ export default (app: Router): void => {
* bio:
* type: string
* required: false
* country:
* type: string
* required: false
* responses:
* "200":
* description: "Success"
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/validators/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const create = celebrate({
overwrite: Joi.boolean().optional(),
recover: Joi.boolean().optional(),
clientId: Joi.string().optional(),
country: Joi.string().optional(),
}),
});

Expand All @@ -43,6 +44,7 @@ const update = celebrate({
Joi.string().email({ tlds: { allow: false } }),
null
).optional(),
country: Joi.string().optional(),
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ module.exports = {
type: Sequelize.STRING(512),
allowNull: true,
},
country: {
type: Sequelize.STRING(64),
allowNull: true,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'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', 'country', {
type: Sequelize.STRING(64),
allowNull: true,
});
},

down(queryInterface, Sequelize) {},
};
4 changes: 4 additions & 0 deletions packages/core/src/database/models/app/appUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class AppUserModel extends Model<AppUser, AppUserCreationAttributes> {
public active!: boolean;
public email!: string;
public bio!: string;
public country!: string;

// timestamps!
public readonly createdAt!: Date;
Expand Down Expand Up @@ -93,6 +94,9 @@ export function initializeAppUser(sequelize: Sequelize): typeof AppUserModel {
bio: {
type: DataTypes.STRING(64),
},
country: {
type: DataTypes.STRING(64),
},
lastLogin: {
type: DataTypes.DATE,
defaultValue: Sequelize.fn('now'),
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/interfaces/app/appUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ import { AppUserTrust, AppUserTrustCreation } from './appUserTrust';
* lastLogin:
* type: date
* description: User last login
* country:
* type: string
* description: User country
* suspect:
* type: boolean
* description: True if user is suspect, set by internal mechanism
Expand Down Expand Up @@ -84,6 +87,7 @@ export interface AppUser {
active: boolean;
email: string;
bio: string;
country: string | null;

// timestamps
createdAt: Date;
Expand All @@ -109,6 +113,7 @@ export interface AppUserUpdate {
children?: number | null;
email?: string;
bio?: string;
country?: string;
}

export interface AppUserCreationAttributes {
Expand All @@ -128,6 +133,7 @@ export interface AppUserCreationAttributes {
active?: boolean;
email?: string;
bio?: string;
country?: string;

trust?: AppUserTrustCreation;
}