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

fix: Store did in cache for resources #373

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions src/controllers/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ResourceController {
check('alsoKnownAs.*.description').isString().withMessage(Messages.Invalid),
];
public static createResourceValidator = [
check('did').exists().isString().contains('did:cheqd').withMessage(Messages.InvalidDid),
check('did').optional().isString().contains('did:cheqd').withMessage(Messages.InvalidDid),
check('jobId')
.custom((value, { req }) => {
if (!value && !(req.body.name && req.body.type && req.body.content)) return false;
Expand All @@ -53,7 +53,7 @@ export class ResourceController {
check('alsoKnownAs.*.description').isString().withMessage(Messages.Invalid),
];
public static updateResourceValidator = [
check('did').exists().isString().contains('did:cheqd').withMessage(Messages.InvalidDid),
check('did').optional().isString().contains('did:cheqd').withMessage(Messages.InvalidDid),
check('jobId')
.custom((value, { req }) => {
if (!value && !(req.body.name && req.body.type && req.body.content)) return false;
Expand Down Expand Up @@ -87,7 +87,7 @@ export class ResourceController {
.json(Responses.GetInvalidResourceResponseV1({}, request.body.secret, result.array()[0].msg));
}

const { did } = request.params;
let { did } = request.params;
let {
jobId,
data,
Expand Down Expand Up @@ -129,6 +129,7 @@ export class ResourceController {
}

resourcePayload = storeData.resource;
did = storeData.did;
resourcePayload.data = new Uint8Array(Object.values(resourcePayload.data!));
} else if (!data) {
return response
Expand All @@ -153,7 +154,7 @@ export class ResourceController {
if (secret.signingResponse) {
signInputs = convertToSignInfo(secret.signingResponse);
} else {
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action });
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action, did });
return response
.status(200)
.json(
Expand Down Expand Up @@ -260,6 +261,7 @@ export class ResourceController {
}

resourcePayload = storeData.resource;
did = storeData.did;
resourcePayload.data = new Uint8Array(Object.values(resourcePayload.data!));
} else if (!content) {
return response
Expand Down Expand Up @@ -289,7 +291,7 @@ export class ResourceController {
if (secret.signingResponse) {
signInputs = convertToSignInfo(secret.signingResponse);
} else {
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action });
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action, did });
return response
.status(200)
.json(
Expand Down Expand Up @@ -376,6 +378,7 @@ export class ResourceController {
}

resourcePayload = storeData.resource;
did = storeData.did;
resourcePayload.data = new Uint8Array(Object.values(resourcePayload.data!));
} else if (!content) {
return response
Expand Down Expand Up @@ -447,7 +450,7 @@ export class ResourceController {
if (secret.signingResponse) {
signInputs = convertToSignInfo(secret.signingResponse);
} else {
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action });
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action, did });
return response
.status(200)
.json(
Expand Down
1 change: 1 addition & 0 deletions src/controllers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ export interface IDidDocData {
export interface IResourceData {
resource: Partial<MsgCreateResourcePayload>;
state: IState;
did: string;
}
Loading