Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-029
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-029
2023-029
Commits
f534c5d5
Commit
f534c5d5
authored
Aug 26, 2023
by
janithgamage1.ed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: update
Desc : user API frontend config
parent
302c6bba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
234 additions
and
3 deletions
+234
-3
Project/Backend/Server_Node/controllers/user.controller.js
Project/Backend/Server_Node/controllers/user.controller.js
+2
-2
Project/Frontend/SignConnectPlus/src/store/reducers/user.ts
Project/Frontend/SignConnectPlus/src/store/reducers/user.ts
+194
-0
Project/Frontend/SignConnectPlus/src/types/nutrition.ts
Project/Frontend/SignConnectPlus/src/types/nutrition.ts
+1
-1
Project/Frontend/SignConnectPlus/src/types/user.ts
Project/Frontend/SignConnectPlus/src/types/user.ts
+37
-0
No files found.
Project/Backend/Server_Node/controllers/user.controller.js
View file @
f534c5d5
...
@@ -129,7 +129,7 @@ export const updateUser = async (req, res) => {
...
@@ -129,7 +129,7 @@ export const updateUser = async (req, res) => {
const
updateUser
=
{
...
data
,
_id
:
id
}
const
updateUser
=
{
...
data
,
_id
:
id
}
await
User
.
findByIdAndUpdate
(
id
,
updateUser
,
{
new
:
true
})
await
User
.
findByIdAndUpdate
(
id
,
updateUser
,
{
new
:
true
})
res
.
status
(
200
);
res
.
status
(
200
);
res
.
json
({
code
:
"
01
"
,
result
:
updateUser
})
res
.
json
({
code
:
"
01
"
,
result
:
updateUser
})
...
@@ -150,7 +150,7 @@ export const deleteUser = async (req, res) => {
...
@@ -150,7 +150,7 @@ export const deleteUser = async (req, res) => {
await
User
.
findByIdAndDelete
(
id
);
await
User
.
findByIdAndDelete
(
id
);
res
.
status
(
200
);
res
.
status
(
200
);
res
.
json
({
code
:
"
01
"
,
"
message
"
:
"
User Deleted Successfully
"
});
res
.
json
({
code
:
"
01
"
,
result
:
id
,
"
message
"
:
"
User Deleted Successfully
"
});
}
catch
(
error
)
{
}
catch
(
error
)
{
res
.
status
(
404
);
res
.
status
(
404
);
res
.
json
({
code
:
"
00
"
,
"
message
"
:
error
.
message
});
res
.
json
({
code
:
"
00
"
,
"
message
"
:
error
.
message
});
...
...
Project/Frontend/SignConnectPlus/src/store/reducers/user.ts
0 → 100644
View file @
f534c5d5
// third-party
import
{
createSlice
}
from
'
@reduxjs/toolkit
'
;
// project imports
import
{
axiosServices
}
from
'
utils/axios
'
;
import
{
dispatch
}
from
'
../index
'
;
// types
import
{
DefaultRootStateProps
,
User
}
from
'
types/user
'
;
// ----------------------------------------------------------------------
const
initialState
:
DefaultRootStateProps
[
'
user
'
]
=
{
error
:
null
,
success
:
null
,
users
:
[],
user
:
null
,
isLoading
:
false
};
const
slice
=
createSlice
({
name
:
'
user
'
,
initialState
,
reducers
:
{
// TO INITIAL STATE
hasInitialState
(
state
)
{
state
.
error
=
null
;
state
.
success
=
null
;
state
.
isLoading
=
false
;
},
// HAS ERROR
hasError
(
state
,
action
)
{
state
.
error
=
action
.
payload
;
},
startLoading
(
state
)
{
state
.
isLoading
=
true
;
},
finishLoading
(
state
)
{
state
.
isLoading
=
false
;
},
// POST USER
addUserSuccess
(
state
,
action
)
{
state
.
users
.
push
(
action
.
payload
.
result
);
state
.
success
=
"
User created successfully.
"
},
// GET USER
fetchUserSuccess
(
state
,
action
)
{
state
.
user
=
action
.
payload
.
result
;
state
.
success
=
null
},
// GET ALL USERS
fetchUsersSuccess
(
state
,
action
)
{
state
.
users
=
action
.
payload
;
state
.
success
=
null
},
// UPDATE USER
updateUserSuccess
(
state
,
action
)
{
const
updatedUserIndex
=
state
.
users
.
findIndex
(
user
=>
user
.
_id
===
action
.
payload
.
result
.
_id
);
if
(
updatedUserIndex
!==
-
1
)
{
state
.
users
[
updatedUserIndex
]
=
action
.
payload
;
}
state
.
success
=
"
User updated successfully.
"
},
// DELETE USER
deleteUserSuccess
(
state
,
action
)
{
state
.
users
=
state
.
users
.
filter
(
user
=>
user
.
_id
!==
action
.
payload
.
result
);
state
.
success
=
"
User deleted successfully.
"
},
}
});
// Reducer
export
default
slice
.
reducer
;
// ----------------------------------------------------------------------
/**
* TO INITIAL STATE
* @returns
*/
export
function
toInitialState
()
{
return
async
()
=>
{
dispatch
(
slice
.
actions
.
hasInitialState
())
}
}
/**
* POST USER
* @param newUser
* @returns
*/
export
function
addUser
(
newUser
:
User
)
{
return
async
()
=>
{
dispatch
(
slice
.
actions
.
startLoading
());
try
{
const
response
=
await
axiosServices
.
post
(
'
/user/sign-up
'
,
newUser
);
dispatch
(
slice
.
actions
.
addUserSuccess
(
response
.
data
));
}
catch
(
error
)
{
dispatch
(
slice
.
actions
.
hasError
(
error
));
}
finally
{
dispatch
(
slice
.
actions
.
finishLoading
());
}
};
}
/**
* GET USER
* @param id
* @returns
*/
export
function
fetchUser
(
id
:
number
)
{
return
async
()
=>
{
dispatch
(
slice
.
actions
.
startLoading
());
try
{
const
response
=
await
axiosServices
.
get
(
`/user/
${
id
}
`
);
dispatch
(
slice
.
actions
.
fetchUserSuccess
(
response
.
data
));
}
catch
(
error
)
{
dispatch
(
slice
.
actions
.
hasError
(
error
));
}
finally
{
dispatch
(
slice
.
actions
.
finishLoading
());
}
};
}
/**
* GET ALL USERS
* @param queryParams
* @returns
*/
export
function
fetchUsers
()
{
return
async
()
=>
{
dispatch
(
slice
.
actions
.
startLoading
());
try
{
const
response
=
await
axiosServices
.
get
(
'
/user/all
'
);
dispatch
(
slice
.
actions
.
fetchUsersSuccess
(
response
.
data
));
}
catch
(
error
)
{
dispatch
(
slice
.
actions
.
hasError
(
error
));
}
finally
{
dispatch
(
slice
.
actions
.
finishLoading
());
}
};
}
/**
* UPDATE USER
* @param updatedUser
* @returns
*/
export
function
updateUser
(
updatedUser
:
User
)
{
return
async
()
=>
{
dispatch
(
slice
.
actions
.
startLoading
());
try
{
const
response
=
await
axiosServices
.
put
(
`/user/
${
updatedUser
.
_id
}
`
,
updateUser
);
dispatch
(
slice
.
actions
.
updateUserSuccess
(
response
.
data
));
}
catch
(
error
)
{
dispatch
(
slice
.
actions
.
hasError
(
error
));
}
finally
{
dispatch
(
slice
.
actions
.
finishLoading
());
}
};
}
/**
* DELETE USER
* @param userId
* @returns
*/
export
function
deleteNutrition
(
userId
:
number
)
{
return
async
()
=>
{
dispatch
(
slice
.
actions
.
startLoading
());
try
{
await
axiosServices
.
delete
(
`/user/
${
userId
}
`
);
dispatch
(
slice
.
actions
.
deleteUserSuccess
(
userId
));
}
catch
(
error
)
{
dispatch
(
slice
.
actions
.
hasError
(
error
));
}
finally
{
dispatch
(
slice
.
actions
.
finishLoading
());
}
};
}
Project/Frontend/SignConnectPlus/src/types/nutrition.ts
View file @
f534c5d5
// Nutrition
s
list
// Nutrition list
export
type
Nutrition
=
{
export
type
Nutrition
=
{
id
:
string
|
number
|
undefined
;
id
:
string
|
number
|
undefined
;
...
...
Project/Frontend/SignConnectPlus/src/types/user.ts
0 → 100644
View file @
f534c5d5
// User Type
export
type
User
=
{
_id
:
string
|
number
|
undefined
;
firstName
:
string
;
lastName
:
string
;
email
:
string
;
contactNumber
:
string
;
type
:
string
;
states
:
number
;
createdAt
:
Date
;
updatedAt
:
Date
;
};
export
type
Users
=
{
_id
:
string
|
number
|
undefined
;
firstName
:
string
;
lastName
:
string
;
email
:
string
;
contactNumber
:
string
;
type
:
string
;
states
:
number
;
createdAt
:
Date
;
updatedAt
:
Date
;
};
export
interface
UserStateProps
{
users
:
Users
[];
user
:
User
|
null
;
error
:
object
|
string
|
null
;
success
:
object
|
string
|
null
;
isLoading
:
boolean
}
export
interface
DefaultRootStateProps
{
user
:
UserStateProps
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment