init
This commit is contained in:
@@ -224,3 +224,32 @@ func (p *UserProcessorImpl) DeactivateUser(ctx context.Context, userID uuid.UUID
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *UserProcessorImpl) UpdateUserOutlet(ctx context.Context, userID uuid.UUID, req *models.UpdateUserOutletRequest) (*models.UserResponse, error) {
|
||||
// Get user first to validate existence and get organization_id
|
||||
existingUser, err := p.userRepo.GetByID(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("user not found: %w", err)
|
||||
}
|
||||
|
||||
// Validate outlet exists
|
||||
outlet, err := p.outletRepo.GetByID(ctx, req.OutletID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("outlet not found: %w", err)
|
||||
}
|
||||
|
||||
// Validate outlet belongs to user's organization
|
||||
if outlet.OrganizationID != existingUser.OrganizationID {
|
||||
return nil, fmt.Errorf("outlet does not belong to user's organization")
|
||||
}
|
||||
|
||||
// Update user's outlet_id
|
||||
existingUser.OutletID = &req.OutletID
|
||||
|
||||
err = p.userRepo.Update(ctx, existingUser)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to update user outlet: %w", err)
|
||||
}
|
||||
|
||||
return mappers.UserEntityToResponse(existingUser), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user