Implement Parent API
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 : https://github.com/LiterateInk/Pawnote/commit/f05fa818d143ee1d838ae13c558ae7273b24570e#diff-bfc1c859dba30aea6586432084f6d67dce2d09659a66accbbd764a3fa773f88c
That mutates the new userResource property on SessionHandle : https://github.com/LiterateInk/Pawnote/commit/f05fa818d143ee1d838ae13c558ae7273b24570e#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.
Sorry for the slow progress on here, during the rewrite I've been able to find a good compromise to implement parents API, as shown in these early commits...
- https://github.com/LiterateInk/Pawnote.js/commit/184df98a82b51737b30ab7a78e25c794b747967f
- https://github.com/LiterateInk/Pawnote.js/commit/b75a01109d257807eff31ff732f1132ad84a7692
Since I'm rewriting this library from the ground up, it may take a bit of time before I actually finish this entirely but I'm pretty sure we'll have something working in a very few months.
Thanks for the update. Let me know if you want me to test anything.
In the meantime, I've done a fork here: https://www.npmjs.com/package/@niicojs/pawnote
To be clear: I'm not saying people should use it! It works for me but my tests and usage are limited.
Yes I saw the fork, it's alright don't worry