So Let's Say I have:
- Timesheet Aggregate
- Member Aggregate (Which have role: Operator and Approver)
In Business Perspective, Operator will create timesheet according to their schedule work.
Previously, I using use case to check whether the role is valid or not
Using Use-Case:
createTimesheetUseCase(props)
member = memberRepository(props.memberId); // assume always return member
if (member.role != ROLE.OPERATOR)
throw ForbiddenCreateTimesheet();
timesheet = TimesheetFactory.create(props);
timesheetRepository.save(timesheet);
But I wonder whether I can create Timesheet aggregate inside the Member Aggregate?
In code maybe something like this:
createTimesheetUseCase(props)
member = memberRepository(memberId); // assume always return member
timesheet = member.createTimesheet(props); // Will throw error if role is not operator
timesheetRepository.save(timesheet);
Inside Member aggregate:
createTimesheet(props)
if (this.role != ROLE.OPERATOR) throw ForbiddenCreateTimesheet();
return TimesheetFactory.create({...props, memberId: this.id});
Is it violated the DDD and what's in your opinion the best way to handle this case ?