Update API responses to 204 (#10441)

* shares.info

* subscriptions and pins to 204
This commit is contained in:
Tom Moor
2025-10-22 23:48:24 +02:00
committed by GitHub
parent a5d065e5ec
commit ff13f1a452
8 changed files with 56 additions and 22 deletions

View File

@@ -37,6 +37,9 @@ export default class PinsStore extends Store<Pin> {
documentId,
collectionId,
});
if (!res) {
return;
}
invariant(res?.data, "Data should be available");
return this.add(res.data);
} catch (err) {

View File

@@ -34,6 +34,9 @@ export default class SubscriptionsStore extends Store<Subscription> {
try {
const res = await client.post(`/${this.apiEndpoint}.info`, options);
if (!res) {
return;
}
invariant(res?.data, "Data should be available");
return this.add(res.data);
} catch (err) {

View File

@@ -227,7 +227,7 @@ describe("#pins.info", () => {
expect(pin.data.collectionId).toEqual(document.collectionId);
});
it("should throw 404 if no pin found", async () => {
it("should return 204 if no pin for input", async () => {
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
@@ -242,7 +242,7 @@ describe("#pins.info", () => {
},
});
expect(res.status).toEqual(404);
expect(res.status).toEqual(204);
});
});

View File

@@ -77,9 +77,13 @@ router.post(
createdById: user.id,
teamId: user.teamId,
},
rejectOnEmpty: true,
});
if (!pin) {
ctx.response.status = 204;
return;
}
ctx.body = {
data: presentPin(pin),
policies: presentPolicies(user, [pin]),

View File

@@ -655,6 +655,20 @@ describe("#shares.info", () => {
expect(body.data.shares[0].id).toBe(share.id);
expect(body.data.shares[0].published).toBe(true);
});
it("should allow reading share by documentId", async () => {
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
const res = await server.post("/api/shares.info", {
body: {
token: user.getJwtToken(),
documentId: document.id,
},
});
expect(res.status).toEqual(204);
});
it("should return share for parent document with includeChildDocuments=true", async () => {
const user = await buildUser();
const collection = await buildCollection({

View File

@@ -102,25 +102,31 @@ router.post(
throw AuthenticationError("Authentication required");
}
const { share, parentShare } = await loadShareWithParent({
collectionId,
documentId,
user,
});
try {
const { share, parentShare } = await loadShareWithParent({
collectionId,
documentId,
user,
});
const shares = [share, parentShare].filter(Boolean) as Share[];
const shares = [share, parentShare].filter(Boolean) as Share[];
if (!shares.length) {
throw NotFoundError();
}
if (!shares.length) {
ctx.response.status = 204;
return;
ctx.body = {
data: {
shares: shares.map((s) => presentShare(s, user.isAdmin ?? false)),
},
policies: presentPolicies(user, shares),
};
} catch (err) {
if (err.id === "not_found") {
ctx.response.status = 204;
return;
}
throw err;
}
ctx.body = {
data: {
shares: shares.map((s) => presentShare(s, user.isAdmin ?? false)),
},
policies: presentPolicies(user, shares),
};
}
);

View File

@@ -300,7 +300,7 @@ describe("#subscriptions.info", () => {
);
});
it("should throw 404 if no subscription found", async () => {
it("should return 204 if no subscription for input", async () => {
const author = await buildUser();
const subscriber = await buildUser({ teamId: author.teamId });
const document = await buildDocument({
@@ -316,7 +316,7 @@ describe("#subscriptions.info", () => {
},
});
expect(res.status).toEqual(404);
expect(res.status).toEqual(204);
});
it("should not allow outsiders to gain info about a subscription", async () => {

View File

@@ -98,9 +98,13 @@ router.post(
// There can be only one subscription with these props.
const subscription = await Subscription.findOne({
where,
rejectOnEmpty: true,
});
if (!subscription) {
ctx.response.status = 204;
return;
}
ctx.body = {
data: presentSubscription(subscription),
};