Skip to content

Commit

Permalink
SPSH-610-klassen-ergebnisliste (#534)
Browse files Browse the repository at this point in the history
* searchstring for Klasse handled differently

* test
  • Loading branch information
YoussefBouch authored Jun 12, 2024
1 parent 64f6e02 commit 51ae7bd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/modules/organisation/api/organisation.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,46 @@ describe('OrganisationController', () => {

expect(result.items.length).toEqual(1);
});
it('should find all organizations that match with Klasse Typ', async () => {
const queryParams: FindOrganisationQueryParams = {
typ: OrganisationsTyp.KLASSE,
searchString: faker.lorem.word(),
systemrechte: [],
administriertVon: [faker.string.uuid(), faker.string.uuid()],
};

const mockedRepoResponse: Counted<Organisation<true>> = [
[
{
id: faker.string.uuid(),
createdAt: faker.date.recent(),
updatedAt: faker.date.recent(),
administriertVon: faker.string.uuid(),
zugehoerigZu: faker.string.uuid(),
kennung: faker.lorem.word(),
name: faker.lorem.word(),
namensergaenzung: faker.lorem.word(),
kuerzel: faker.lorem.word(),
typ: OrganisationsTyp.KLASSE,
traegerschaft: Traegerschaft.LAND,
},
],
1,
];

const permissionsMock: DeepMocked<PersonPermissions> = createMock<PersonPermissions>();
permissionsMock.getOrgIdsWithSystemrecht.mockResolvedValueOnce([]);

organisationRepositoryMock.findBy.mockResolvedValue(mockedRepoResponse);

const result: Paged<OrganisationResponse> = await organisationController.findOrganizations(
queryParams,
permissionsMock,
);

expect(organisationRepositoryMock.findBy).toHaveBeenCalledTimes(1);
expect(result.items.length).toEqual(1);
});
});
});

Expand Down
20 changes: 19 additions & 1 deletion src/modules/organisation/api/organisation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { DbiamOrganisationError } from './dbiam-organisation.error.js';
import { OrganisationExceptionFilter } from './organisation-exception-filter.js';
import { OrganisationSpecificationError } from '../specification/error/organisation-specification.error.js';
import { OrganisationByIdQueryParams } from './organisation-by-id.query.js';
import { OrganisationsTyp } from '../domain/organisation.enums.js';

@UseFilters(new SchulConnexValidationErrorFilter(), new OrganisationExceptionFilter())
@ApiTags('organisationen')
Expand Down Expand Up @@ -192,7 +193,24 @@ export class OrganisationController {
true,
);

const scope: OrganisationScope = new OrganisationScope()
const scope: OrganisationScope = new OrganisationScope();

// If the typ is Klasse then only search by Name using the search string
if (queryParams.typ === OrganisationsTyp.KLASSE) {
scope
.findBy({
kennung: queryParams.kennung,
name: queryParams.name,
typ: queryParams.typ,
})
.setScopeWhereOperator(ScopeOperator.AND)
.findByAdministriertVonArray(queryParams.administriertVon)
.searchStringAdministriertVon(queryParams.searchString)
.excludeTyp(queryParams.excludeTyp)
.byIDs(validOrgaIDs)
.paged(queryParams.offset, queryParams.limit);
}
scope
.findBy({
kennung: queryParams.kennung,
name: queryParams.name,
Expand Down

0 comments on commit 51ae7bd

Please sign in to comment.