Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
saadshams committed Sep 2, 2024
1 parent b67f945 commit a7b4f2b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ WORKDIR /service
COPY package*.json ./
COPY . .

# DEVELOPMENT
# DEVELOPMENT - Enable Volume in docker-compose.yml
#ENV NODE_ENV development
## Enable Volume in docker-compose.yml
#RUN npm install
#CMD ["npx", "nodemon", "npm", "start"]

Expand Down
5 changes: 3 additions & 2 deletions src/model/ServiceProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ServiceProxy extends Proxy {
try {
await this.mySQL.beginTransaction(connection);
const result = await this.user.add(connection, user);
if (user.roles)
if (user.roles && user.roles.length > 0)
await this.role.updateRolesById(connection, result.body.id, user.roles);
await this.mySQL.commit(connection);
return result;
Expand All @@ -65,7 +65,8 @@ export class ServiceProxy extends Proxy {
const result = await this.user.update(connection, user);
if (user.roles) {
await this.role.deleteRolesById(connection, user.id);
await this.role.updateRolesById(connection, user.id, user.roles)
if (user.roles.length > 0)
await this.role.updateRolesById(connection, user.id, user.roles)
}
await this.mySQL.commit(connection);
result.body = user;
Expand Down
2 changes: 1 addition & 1 deletion src/model/data/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Role {
let sql = "INSERT INTO user_role(user_id, role_id) VALUES ?;"
let values = roles.map(({id, name}) => [userId, id]);
connection.query(sql, [values], (error, result) => {
error ? reject({status: 500, body: error}) : resolve({status: 200, body: roles});
error ? reject({status: 500, body: error.sqlMessage}) : resolve({status: 200, body: roles});
});
});
}
Expand Down

0 comments on commit a7b4f2b

Please # to comment.