Skip to content

Commit deccb98

Browse files
author
Niloy Deb Roy
committed
Add check for if company is aleady attached to user when user is attaching company
1 parent 05f5d64 commit deccb98

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

api/v1/user.go

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (u userApi) registerUser(context echo.Context) error {
252252
if err := formData.ResourcePermission.Validate(); err != nil {
253253
return common.GenerateErrorResponse(context, err.Error(), "Please give valid user resource permission data!")
254254
}
255+
formData.Metadata.CompanyId = userResourcePermission.Metadata.CompanyId
255256
formData.CreatedDate = time.Now().UTC()
256257
formData.UpdatedDate = time.Now().UTC()
257258
formData.Status=enums.ACTIVE

core/v1/logic/user.go

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func (u userService) AttachCompany(company v1.Company, companyId, token string)
3636
if tokenObject.Uid==""{
3737
return errors.New("no token found")
3838
}
39+
user := u.userRepo.GetByID(tokenObject.Uid)
40+
if user.Metadata.CompanyId != "" {
41+
return errors.New("[ERROR]: User already got company id attached")
42+
}
3943
if config.ApplicationCreationEnabled {
4044
marshal, marshalErr := json.Marshal(company)
4145
if marshalErr != nil {

core/v1/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type RoleUpdateOption struct {
8686

8787
func GetUserFromUserRegistrationDto(u UserRegistrationDto) User {
8888
user := User{
89+
Metadata: UserMetadata{CompanyId: u.Metadata.CompanyId},
8990
ID: u.ID,
9091
FirstName: u.FirstName,
9192
LastName: u.LastName,

0 commit comments

Comments
 (0)