updated user management
This commit is contained in:
@@ -1,21 +1,25 @@
|
||||
class UserResource {
|
||||
constructor(user) {
|
||||
this.id = user?.id ?? null
|
||||
this.name = user?.name ?? null
|
||||
this.email = user?.email ?? null
|
||||
this.phone = user?.phone ?? null
|
||||
//this.role = user?.role ?? null
|
||||
this.via = user?.login_via ?? null
|
||||
this.google_id = user?.google_id ?? null
|
||||
this.last_login = user?.last_login ?? null
|
||||
this.created_at = user?.created_at ?? null
|
||||
this.updated_at = user?.updated_at ?? null
|
||||
this.id = user?.id ?? null;
|
||||
this.name = user?.name ?? null;
|
||||
this.email = user?.email ?? null;
|
||||
this.phone = user?.phone ?? null;
|
||||
this.role = user?.role ?? null;
|
||||
this.branch_name = user?.branch?.name ?? null; // ambil langsung nama cabang
|
||||
this.avatar_url = user?.avatar_url ?? null;
|
||||
this.via = user?.login_via ?? null;
|
||||
this.is_suspended = user?.is_suspended ?? null;
|
||||
this.is_first_login = user?.is_first_login ?? null;
|
||||
this.birth = user?.birth ?? null;
|
||||
this.last_login = user?.last_login ?? null;
|
||||
this.created_at = user?.created_at ?? null;
|
||||
this.updated_at = user?.updated_at ?? null;
|
||||
}
|
||||
|
||||
|
||||
static collection(users) {
|
||||
return users.map(user => new UserResource(user));
|
||||
return users.map((user) => new UserResource(user));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = UserResource
|
||||
}
|
||||
|
||||
module.exports = UserResource;
|
||||
|
||||
@@ -3,6 +3,7 @@ const response = require('../../helpers/responses')
|
||||
const errorHandler = require('../../middlewares/errorHandler')
|
||||
const db = require('../../../models/migration')
|
||||
const User = db.User
|
||||
const Branch = db.Branch
|
||||
const {Op} = require('sequelize')
|
||||
const bcrypt = require('bcrypt')
|
||||
const UserResource = require('../resources/user.resource')
|
||||
@@ -51,6 +52,13 @@ const index = async (req, res) => {
|
||||
}
|
||||
const user = await User.findAll({
|
||||
where,
|
||||
include: [
|
||||
{
|
||||
model: Branch,
|
||||
as: 'branch',
|
||||
attributes: ['name'],
|
||||
},
|
||||
],
|
||||
order: [['created_at', 'DESC']]
|
||||
})
|
||||
return response.success(res, UserResource.collection(user), 'Loaded Successfuly')
|
||||
|
||||
Reference in New Issue
Block a user