|
@@ -177,6 +177,48 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) |
|
@@ -177,6 +177,48 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) |
177
|
}
|
177
|
}
|
178
|
}
|
178
|
}
|
179
|
|
179
|
|
|
|
180
|
+func (repository *EmployeeRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) {
|
|
|
181
|
+ tx := repository.transactionContext.PgTx
|
|
|
182
|
+ var employeeModels []*models.Employee
|
|
|
183
|
+ employees := make([]*domain.Employee, 0)
|
|
|
184
|
+ query := tx.Model(&employeeModels)
|
|
|
185
|
+ if companyId, ok := queryOptions["companyId"]; ok {
|
|
|
186
|
+ query = query.Where("employee.company_id = ?", companyId)
|
|
|
187
|
+ }
|
|
|
188
|
+ if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") {
|
|
|
189
|
+ query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string)))
|
|
|
190
|
+ }
|
|
|
191
|
+ if ids, ok := queryOptions["ids"]; ok && len(ids.([]int)) != 0 {
|
|
|
192
|
+ query = query.Where("employee.uid IN (?)", pg.In(ids.([]int)) )
|
|
|
193
|
+ }
|
|
|
194
|
+ if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
|
|
|
195
|
+ if personNameMatch, ok := where.(map[string]interface{})["personNameMatch"]; ok && (personNameMatch != "") {
|
|
|
196
|
+ query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", personNameMatch.(string)))
|
|
|
197
|
+ }
|
|
|
198
|
+ if companyId, ok := where.(map[string]interface{})["companyId"]; ok && companyId.(float64) != 0 {
|
|
|
199
|
+ query = query.Where("employee.company_id = ?", companyId)
|
|
|
200
|
+ }
|
|
|
201
|
+ }
|
|
|
202
|
+ if status, ok := queryOptions["status"]; ok && status.(int) != 0 {
|
|
|
203
|
+ query = query.Where(`employee.status = ?`, status)
|
|
|
204
|
+ }
|
|
|
205
|
+ if isPrincipal, ok := queryOptions["isPrincipal"]; ok && isPrincipal.(bool) != false {
|
|
|
206
|
+ query = query.Where("employee.is_principal = ? ", isPrincipal)
|
|
|
207
|
+ }
|
|
|
208
|
+ if count, err := query.Order("uid DESC").SelectAndCount(); err != nil {
|
|
|
209
|
+ return 0, employees, err
|
|
|
210
|
+ } else {
|
|
|
211
|
+ for _, employeeModel := range employeeModels {
|
|
|
212
|
+ if employee, err := repository.transformPgModelToDomainModel(employeeModel); err != nil {
|
|
|
213
|
+ return 0, employees, err
|
|
|
214
|
+ } else {
|
|
|
215
|
+ employees = append(employees, employee)
|
|
|
216
|
+ }
|
|
|
217
|
+ }
|
|
|
218
|
+ return int64(count), employees, nil
|
|
|
219
|
+ }
|
|
|
220
|
+}
|
|
|
221
|
+
|
180
|
func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeModel *models.Employee) (*domain.Employee, error) {
|
222
|
func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeModel *models.Employee) (*domain.Employee, error) {
|
181
|
return &domain.Employee{
|
223
|
return &domain.Employee{
|
182
|
EmployeeId: employeeModel.Id,
|
224
|
EmployeeId: employeeModel.Id,
|