Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove short ID #2148

Merged
merged 25 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8a737ea
reduced usage of short id in code
TheSlimvReal Jan 2, 2024
e352f99
fixed some bugs
TheSlimvReal Jan 2, 2024
c2e8a9d
fixed view issues
TheSlimvReal Jan 2, 2024
212f68d
fixed tests
TheSlimvReal Jan 2, 2024
fed3556
removed furhter usages of short id
TheSlimvReal Jan 2, 2024
4197c8e
removed furhter usages of short id in tests
TheSlimvReal Jan 2, 2024
c518c43
flipped function attribute meaning of `getId()`
TheSlimvReal Jan 2, 2024
86c4db0
Merge branch 'master' into remove_short_id
TheSlimvReal Jan 2, 2024
f4757c2
small cleanups
TheSlimvReal Jan 3, 2024
44e5df0
removed trivial function
TheSlimvReal Jan 6, 2024
f972732
entity details support full ids
TheSlimvReal Jan 6, 2024
e3d1418
Merge branch 'master' into remove_short_id
TheSlimvReal Jan 6, 2024
32efef0
Merge branch 'master' into remove_short_id
TheSlimvReal Jan 15, 2024
3ff33f1
added datatype config for educational material
TheSlimvReal Jan 16, 2024
ab6021a
fixed showInactive logic in ChildSchoolOverview
TheSlimvReal Jan 16, 2024
40c67a6
removed some todos
TheSlimvReal Jan 16, 2024
6e1b239
todo completion displays entity `toString`
TheSlimvReal Jan 16, 2024
a08b5b5
report title is optional
TheSlimvReal Jan 16, 2024
294b3d3
removed addPrefix function from query service
TheSlimvReal Jan 16, 2024
4701c92
Merge branch 'master' into remove_short_id
sleidig Jan 22, 2024
7e8848d
Merge branch 'master' into remove_short_id
TheSlimvReal Jan 23, 2024
250bf8f
fixed completedBy issue
TheSlimvReal Jan 23, 2024
4c2f3c9
removed duplicate test
TheSlimvReal Jan 23, 2024
6ff37db
review cleanups
TheSlimvReal Jan 23, 2024
ed70ebb
Merge branch 'master' into remove_short_id
TheSlimvReal Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const demoChildren = [
];

const simpleEvent = Note.create(new Date(), "some meeting");
demoChildren.forEach((c) => simpleEvent.addChild(c.getId()));
demoChildren.forEach((c) => simpleEvent.addChild(c));

const longEvent = Note.create(new Date(), "another meeting");
longEvent.text =
Expand All @@ -40,12 +40,11 @@ longEvent.category = {
label: "Guardians Meeting",
isMeeting: true,
};
demoChildren.forEach((c) => longEvent.addChild(c.getId()));
demoChildren.forEach((c) => longEvent.addChild(c));

const activityEvent = Note.create(new Date(), "Coaching Batch C");
activityEvent.relatesTo =
RecurringActivity.create("Coaching Batch C").getId(true);
demoChildren.forEach((c) => activityEvent.addChild(c.getId()));
activityEvent.relatesTo = RecurringActivity.create("Coaching Batch C").getId();
demoChildren.forEach((c) => activityEvent.addChild(c));

export const OneTimeEvent = Template.bind({});
OneTimeEvent.args = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AttendanceService } from "../../attendance.service";
import { EventNote } from "../../model/event-note";
import { MockedTestingModule } from "../../../../utils/mocked-testing.module";
import { TEST_USER } from "../../../../core/user/demo-user-generator.service";
import { User } from "../../../../core/user/user";

describe("RollCallSetupComponent", () => {
let component: RollCallSetupComponent;
Expand Down Expand Up @@ -64,8 +65,12 @@ describe("RollCallSetupComponent", () => {
flush();

expect(component.existingEvents.length).toBe(2);
expect(component.existingEvents[0].authors).toEqual([TEST_USER]);
expect(component.existingEvents[1].authors).toEqual([TEST_USER]);
expect(component.existingEvents[0].authors).toEqual([
`${User.ENTITY_TYPE}:${TEST_USER}`,
]);
expect(component.existingEvents[1].authors).toEqual([
`${User.ENTITY_TYPE}:${TEST_USER}`,
]);
}));

it("should only show active activities", fakeAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class RollCallSetupComponent implements OnInit {
private async createEventForActivity(
activity: RecurringActivity,
): Promise<NoteForActivitySetup> {
if (this.existingEvents.find((e) => e.relatesTo === activity.getId(true))) {
if (this.existingEvents.find((e) => e.relatesTo === activity.getId())) {
return undefined;
}

Expand All @@ -166,7 +166,7 @@ export class RollCallSetupComponent implements OnInit {
let score = 0;

const activityAssignedUsers = this.allActivities.find(
(a) => a.getId(true) === event.relatesTo,
(a) => a.getId() === event.relatesTo,
)?.assignedTo;
// use parent activities' assigned users and only fall back to event if necessary
const assignedUsers = activityAssignedUsers ?? event.authors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const demoChildren = [
DemoChildGenerator.generateEntity("2"),
DemoChildGenerator.generateEntity("3"),
];
demoChildren.forEach((c) => demoEvent.addChild(c.getId()));
demoChildren.forEach((c) => demoEvent.addChild(c));

const demoActivities = [
DemoActivityGeneratorService.generateActivityForChildren(demoChildren),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe("RollCallComponent", () => {
it("should not record attendance if childId does not exist", fakeAsync(() => {
const nonExistingChildId = "notExistingChild";
const noteWithNonExistingChild = new Note();
noteWithNonExistingChild.addChild(participant1.getId());
noteWithNonExistingChild.addChild(participant1);
noteWithNonExistingChild.addChild(nonExistingChildId);
component.eventEntity = noteWithNonExistingChild;

Expand All @@ -113,8 +113,8 @@ describe("RollCallComponent", () => {

it("should correctly assign the attendance", fakeAsync(() => {
const note = new Note("noteWithAttendance");
note.addChild(participant1.getId());
note.addChild(participant2.getId());
note.addChild(participant1);
note.addChild(participant2);

component.eventEntity = note;
component.ngOnChanges(dummyChanges);
Expand All @@ -124,16 +124,16 @@ describe("RollCallComponent", () => {
tick(1000);
component.markAttendance(ABSENT);

expect(note.getAttendance(participant1.getId()).status).toEqual(PRESENT);
expect(note.getAttendance(participant2.getId()).status).toEqual(ABSENT);
expect(note.getAttendance(participant1).status).toEqual(PRESENT);
expect(note.getAttendance(participant2).status).toEqual(ABSENT);
flush();
}));

it("should mark roll call as done when all existing children are finished", fakeAsync(() => {
const note = new Note();
note.addChild(participant1.getId());
note.addChild(participant1);
note.addChild("notExistingChild");
note.addChild(participant2.getId());
note.addChild(participant2);

spyOn(component.complete, "emit");
component.eventEntity = note;
Expand Down Expand Up @@ -245,7 +245,7 @@ describe("RollCallComponent", () => {
) {
const event = new Note();
for (const p of participantsInput) {
event.addChild(p.getId());
event.addChild(p);
}
component.eventEntity = event;
component.ngOnChanges(dummyChanges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ describe("AttendanceCalendarComponent", () => {
const childWithoutAttendance = new Child("childWithoutAttendance");
const note = new Note();
note.date = new Date();
note.addChild(attendedChild.getId());
note.addChild(absentChild.getId());
note.addChild(childWithoutAttendance.getId());
note.addChild(attendedChild);
note.addChild(absentChild);
note.addChild(childWithoutAttendance);
const presentAttendance = defaultAttendanceStatusTypes.find(
(it) => it.id === "PRESENT",
);
const absentAttendance = defaultAttendanceStatusTypes.find(
(it) => it.id === "ABSENT",
);
note.getAttendance(attendedChild.getId()).status = presentAttendance;
note.getAttendance(absentChild.getId()).status = absentAttendance;
note.getAttendance(attendedChild).status = presentAttendance;
note.getAttendance(absentChild).status = absentAttendance;
component.records = [note];

component.selectDay(new Date());
Expand Down
21 changes: 9 additions & 12 deletions src/app/child-dev-project/attendance/attendance.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ describe("AttendanceService", () => {
activity1 = RecurringActivity.create("activity 1");
activity2 = RecurringActivity.create("activity 2");

e1_1 = createEvent(moment("2020-01-01").toDate(), activity1.getId(true));
e1_2 = createEvent(moment("2020-01-02").toDate(), activity1.getId(true));
e1_3 = createEvent(moment("2020-03-02").toDate(), activity1.getId(true));
e2_1 = createEvent(moment("2020-01-01").toDate(), activity2.getId(true));
e1_1 = createEvent(moment("2020-01-01").toDate(), activity1.getId());
e1_2 = createEvent(moment("2020-01-02").toDate(), activity1.getId());
e1_3 = createEvent(moment("2020-03-02").toDate(), activity1.getId());
e2_1 = createEvent(moment("2020-01-01").toDate(), activity2.getId());

TestBed.configureTestingModule({
imports: [DatabaseTestingModule],
Expand Down Expand Up @@ -186,15 +186,13 @@ describe("AttendanceService", () => {

expect(actualAttendences).toHaveSize(2);
expectEntitiesToMatch(
actualAttendences.find(
(t) => t.activity.getId(true) === activity1.getId(true),
).events,
actualAttendences.find((t) => t.activity.getId() === activity1.getId())
.events,
[e1_1, e1_2],
);
expectEntitiesToMatch(
actualAttendences.find(
(t) => t.activity.getId(true) === activity2.getId(true),
).events,
actualAttendences.find((t) => t.activity.getId() === activity2.getId())
.events,
[e2_1],
);

Expand Down Expand Up @@ -300,7 +298,6 @@ describe("AttendanceService", () => {
const event = await service.createEventForActivity(activity, date);

expect(mockQueryRelationsOf).toHaveBeenCalledWith(
"school",
linkedSchool.getId(),
date,
);
Expand All @@ -319,7 +316,7 @@ describe("AttendanceService", () => {
duplicateChildRelation.childId = duplicateChild.getId();
duplicateChildRelation.schoolId = linkedSchool.getId();
const anotherRelation = new ChildSchoolRelation();
anotherRelation.childId = "another child id";
anotherRelation.childId = "Child:another_child_id";
anotherRelation.schoolId = linkedSchool.getId();
await entityMapper.saveAll([duplicateChildRelation, anotherRelation]);

Expand Down
15 changes: 5 additions & 10 deletions src/app/child-dev-project/attendance/attendance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ export class AttendanceService {
return attMonth;
}

const events = await this.getEventsForActivity(
activity.getId(true),
sinceDate,
);
const events = await this.getEventsForActivity(activity.getId(), sinceDate);

for (const event of events) {
const record = getOrCreateAttendancePeriod(event);
Expand Down Expand Up @@ -232,10 +229,8 @@ export class AttendanceService {
childId,
);

const visitedSchools = await this.childrenService.queryActiveRelationsOf(
"child",
childId,
);
const visitedSchools =
await this.childrenService.queryActiveRelationsOf(childId);
for (const currentRelation of visitedSchools) {
const activitiesThroughRelation = await this.dbIndexing.queryIndexDocs(
RecurringActivity,
Expand Down Expand Up @@ -266,7 +261,7 @@ export class AttendanceService {
date,
);
instance.schools = activity.linkedGroups;
instance.relatesTo = activity.getId(true);
instance.relatesTo = activity.getId();
instance.category = activity.type;
return instance;
}
Expand Down Expand Up @@ -296,7 +291,7 @@ export class AttendanceService {
): Promise<string[]> {
const childIdPromises = linkedGroups.map((groupId) =>
this.childrenService
.queryActiveRelationsOf("school", groupId, date)
.queryActiveRelationsOf(groupId, date)
.then((relations) =>
relations.map((r) => r.childId).filter((id) => !!id),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DemoActivityEventsGeneratorService extends DemoDataGenerator<EventN
const eventNote = EventNote.create(date, activity.title);
eventNote.authors = activity.assignedTo;
eventNote.category = activity.type;
eventNote.relatesTo = activity.getId(true); // relatesTo requires the id including prefix!
eventNote.relatesTo = activity.getId(); // relatesTo requires the id including prefix!

for (const participantId of activity.participants) {
eventNote.addChild(participantId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,6 @@ export function generateEventWithAttendance(
event.getAttendance(att[0]).remarks = att[2];
}
}
event.relatesTo = activity?.getId(true);
event.relatesTo = activity?.getId();
return event;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import moment from "moment";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
import { DynamicComponent } from "../../../../core/config/dynamic-components/dynamic-component.decorator";
import {
ScreenWidthObserver,
ScreenSize,
ScreenWidthObserver,
} from "../../../../utils/media/screen-size-observer.service";
import { NgForOf, SlicePipe } from "@angular/common";
import { AttendanceBlockComponent } from "../../../attendance/attendance-block/attendance-block.component";
Expand Down
Loading