Implement Parent API
Opened this issue · 7 comments
It would be nice to implement parent api.
From the very limited tests I've done, it seems to be the student api with an additionnal field in signature to tell which resource to impersonate.
Adding those few lines in request-function.ts
did the trick in my little test:
if (this.session?.user && this.data?._Signature_) {
if (this.session.information.accountKind === AccountKind.PARENT) {
this.data._Signature_.membre = {
N: this.session.user.resources.at(0)?.id,
G: 4,
};
}
}
I don't know what the 4 is for :)
In the request you showed, membre
corresponds to the kid you want to get the values from.
N
is the ID of resource and G: 4
is the kind of the resource. 4
means Student
, you can see it in ~/models/entity-kind
-> EntityKind.Student
.
Ok so more like:
if (this.session?.user && this.data?._Signature_) {
if (this.session.information.accountKind === AccountKind.PARENT) {
const kid = this.session.user.resources.at(0);
this.data._Signature_.membre = {
N: kid?.id,
G: kid?.kind,
};
}
}
Yes it would work, I wonder which requests requires this.
Also I wonder where I should let the developer switch to/use another resource (kid for example)...
I'm thinking of a state in SessionHandle
that holds the index of the resource the developer wants to use and it should default to 0
.
You could switch by doing pronote.use(index: number): void
or session.resourceUsed = index
.
API requests will then use that value from session
to do requests depending on the account kind.
Decided to go on this use
helper : f05fa81#diff-bfc1c859dba30aea6586432084f6d67dce2d09659a66accbbd764a3fa773f88c
That mutates the new userResource
property on SessionHandle
: f05fa81#diff-21f9f474e3b5519d91463808fdacc417f872fab6926b43f5447d1cb23bc5937c
That allows for simpler retrieving of the current selected user, that's very cool since it cleans up a lot of the code !
Now, I have to write the differences in requests for parents only.
looks good
From what I can see navigating through the pronote web site, the membre
field is present each time there is a _Signature_
present.