Skip to content

Commit 374ea3d

Browse files
committed
new url field errors fixed, parentSlug and grandparentSlug filter for projects and subprojects
1 parent 67b341d commit 374ea3d

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

backend/src/database/repositories/segmentRepository.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { IRepositoryOptions } from './IRepositoryOptions'
55
import { RepositoryBase } from './repositoryBase'
66
import {
77
SegmentCreateData,
8-
SegmentCriteria,
98
SegmentData,
109
SegmentLevel,
1110
SegmentProjectGroupNestedData,
@@ -48,7 +47,7 @@ class SegmentRepository extends RepositoryBase<
4847
{
4948
replacements: {
5049
id: uuid(),
51-
url: data.url,
50+
url: data.url || null,
5251
name: data.name,
5352
parentName: data.parentName || null,
5453
grandparentName: data.grandparentName || null,
@@ -402,7 +401,7 @@ class SegmentRepository extends RepositoryBase<
402401
}
403402

404403
if (criteria.filter?.name) {
405-
searchQuery += `AND s.name like :name`
404+
searchQuery += `AND s.name ilike :name`
406405
}
407406

408407
const projectGroups = await this.options.database.sequelize.query(
@@ -447,7 +446,7 @@ class SegmentRepository extends RepositoryBase<
447446
},
448447
)
449448

450-
const count = projectGroups.length > 0 ? projectGroups[0].totalCount : 0
449+
const count = projectGroups.length > 0 ? Number.parseInt(projectGroups[0].totalCount, 10) : 0
451450

452451
const rows = projectGroups.map((i) => removeFieldsFromObject(i, 'totalCount'))
453452

@@ -464,7 +463,11 @@ class SegmentRepository extends RepositoryBase<
464463
}
465464

466465
if (criteria.filter?.name) {
467-
searchQuery += ` AND s.name like :name`
466+
searchQuery += ` AND s.name ilike :name`
467+
}
468+
469+
if (criteria.filter?.parentSlug) {
470+
searchQuery += ` AND s."parentSlug" ilike :parent_slug `
468471
}
469472

470473
const projects = await this.options.database.sequelize.query(
@@ -487,12 +490,13 @@ class SegmentRepository extends RepositoryBase<
487490
replacements: {
488491
name: `${criteria.filter?.name}%`,
489492
status: criteria.filter?.status,
493+
parent_slug: `${criteria.filter?.parentSlug}%`,
490494
},
491495
type: QueryTypes.SELECT,
492496
},
493497
)
494498

495-
const count = projects.length > 0 ? projects[0].totalCount : 0
499+
const count = projects.length > 0 ? Number.parseInt(projects[0].totalCount, 10) : 0
496500

497501
const rows = projects.map((i) => removeFieldsFromObject(i, 'totalCount'))
498502

@@ -514,7 +518,15 @@ class SegmentRepository extends RepositoryBase<
514518
}
515519

516520
if (criteria.filter?.name) {
517-
searchQuery += ` AND s.name like :name`
521+
searchQuery += ` AND s.name ilike :name`
522+
}
523+
524+
if (criteria.filter?.parentSlug) {
525+
searchQuery += ` AND s."parentSlug" ilike :parent_slug `
526+
}
527+
528+
if (criteria.filter?.grandparentSlug) {
529+
searchQuery += ` AND s."grandparentSlug" ilike :grandparent_slug `
518530
}
519531

520532
const subprojects = await this.options.database.sequelize.query(
@@ -534,12 +546,14 @@ class SegmentRepository extends RepositoryBase<
534546
tenantId: this.currentTenant.id,
535547
name: `${criteria.filter?.name}%`,
536548
status: criteria.filter?.status,
549+
parent_slug: `${criteria.filter?.parentSlug}%`,
550+
grandparent_slug: `${criteria.filter?.grandparentSlug}%`,
537551
},
538552
type: QueryTypes.SELECT,
539553
},
540554
)
541555

542-
const count = subprojects.length > 0 ? subprojects[0].totalCount : 0
556+
const count = subprojects.length > 0 ? Number.parseInt(subprojects[0].totalCount, 10) : 0
543557

544558
const rows = subprojects.map((i) => {
545559
const subproject = removeFieldsFromObject(i, 'totalCount')

backend/src/database/repositories/tenantRepository.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,22 @@ class TenantRepository {
261261

262262
if (!(await isFeatureEnabled(FeatureFlag.SEGMENTS, { ...options, currentTenant: record }))) {
263263
// return default segment
264-
segmentsFound = [await segmentRepository.getDefaultSegment()]
264+
const defaultSegment = await segmentRepository.getDefaultSegment()
265+
segmentsFound = defaultSegment ? [defaultSegment] : []
265266
} else if (segments.length > 0) {
266267
segmentsFound = await segmentRepository.findInIds(segments)
267268
} else {
268269
// no segment info sent, return all segments
269270
segmentsFound = (await segmentRepository.querySubprojects({})).rows
270271
}
271272

272-
if (record && record.settings && record.settings[0] && record.settings[0].dataValues) {
273+
if (
274+
record &&
275+
record.settings &&
276+
record.settings[0] &&
277+
record.settings[0].dataValues &&
278+
segmentsFound.length > 0
279+
) {
273280
record.settings[0].dataValues.activityTypes = SegmentRepository.getActivityTypes({
274281
...options,
275282
currentTenant: record,

0 commit comments

Comments
 (0)