Skip to content

Commit

Permalink
fix: Use domain field instead of one in JSON (#944)
Browse files Browse the repository at this point in the history
* fix: Use domain field instead of one in JSON

* fix tests

* remove unwanted import
  • Loading branch information
ChaituVR authored Oct 10, 2024
1 parent 2313dac commit e046e4e
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/graphql/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function checkLimits(args: any = {}, type) {
export function formatSpace({
id,
settings,
domain,
verified,
turbo,
flagged,
Expand All @@ -72,6 +73,7 @@ export function formatSpace({
const space = { ...jsonParse(settings, {}), ...spaceMetadata.counts };

space.id = id;
space.domain = domain || '';
space.private = space.private || false;
space.avatar = space.avatar || '';
space.about = space.about || '';
Expand Down Expand Up @@ -403,6 +405,7 @@ export function formatProposal(proposal) {
proposal.space = formatSpace({
id: proposal.space,
settings: proposal.settings,
domain: proposal.spaceDomain,
verified: proposal.spaceVerified,
turbo: proposal.spaceTurbo,
flagged: proposal.spaceFlagged,
Expand All @@ -426,6 +429,7 @@ export function formatVote(vote) {
vote.vp_by_strategy = jsonParse(vote.vp_by_strategy, []);
vote.space = formatSpace({
id: vote.space,
domain: vote.spaceDomain,
settings: vote.settings,
verified: vote.spaceVerified,
turbo: vote.spaceTurbo,
Expand All @@ -439,6 +443,7 @@ export function formatFollow(follow) {
follow.space = formatSpace({
id: follow.space,
settings: follow.settings,
domain: follow.spaceDomain,
verified: follow.spaceVerified,
turbo: follow.spaceTurbo,
flagged: follow.spaceFlagged,
Expand All @@ -451,6 +456,7 @@ export function formatSubscription(subscription) {
subscription.space = formatSpace({
id: subscription.space,
settings: subscription.settings,
domain: subscription.spaceDomain,
verified: subscription.spaceVerified,
turbo: subscription.spaceTurbo,
flagged: subscription.spaceFlagged,
Expand Down
1 change: 1 addition & 0 deletions src/graphql/operations/follows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default async function (parent, args) {
const query = `
SELECT f.*,
spaces.settings,
spaces.domain as spaceDomain,
spaces.flagged as spaceFlagged,
spaces.verified as spaceVerified,
spaces.turbo as spaceTurbo,
Expand Down
1 change: 1 addition & 0 deletions src/graphql/operations/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default async function (parent, { id }) {
const query = `
SELECT p.*,
spaces.settings,
spaces.domain as spaceDomain,
spaces.flagged as spaceFlagged,
spaces.verified as spaceVerified,
spaces.turbo as spaceTurbo,
Expand Down
1 change: 1 addition & 0 deletions src/graphql/operations/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default async function (parent, args) {
const query = `
SELECT p.*,
spaces.settings,
spaces.domain as spaceDomain,
spaces.flagged as spaceFlagged,
spaces.verified as spaceVerified,
spaces.turbo as spaceTurbo,
Expand Down
1 change: 1 addition & 0 deletions src/graphql/operations/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default async function (parent, args) {
const query = `
SELECT s.*,
spaces.settings,
spaces.domain as spaceDomain,
spaces.flagged as spaceFlagged,
spaces.verified as spaceVerified,
spaces.turbo as spaceTurbo,
Expand Down
1 change: 1 addition & 0 deletions src/graphql/operations/votes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async function query(parent, args, context?, info?) {
const query = `
SELECT p.*,
spaces.settings,
spaces.domain as spaceDomain,
spaces.flagged as spaceFlagged,
spaces.verified as spaceVerified,
spaces.turbo as spaceTurbo,
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async function loadSpacesMetrics() {

export async function getSpace(id: string) {
const query = `
SELECT settings, flagged, verified, turbo, hibernated, deleted, follower_count, proposal_count, vote_count
SELECT settings, domain, flagged, verified, turbo, hibernated, deleted, follower_count, proposal_count, vote_count
FROM spaces
WHERE id = ?
LIMIT 1`;
Expand All @@ -279,6 +279,7 @@ export async function getSpace(id: string) {

return {
...JSON.parse(space.settings),
domain: space.domain,
flagged: space.flagged === 1,
verified: space.verified === 1,
turbo: space.turbo === 1,
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/space.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('GET /api/space/:key', () => {
turbo: space.turbo,
hibernated: space.hibernated,
deleted: false,
domain: space.domain,
...space.settings
};

Expand Down Expand Up @@ -76,6 +77,7 @@ describe('GET /api/space/:key', () => {
turbo: space.turbo,
hibernated: space.hibernated,
deleted: true,
domain: space.domain,
...space.settings
};

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const fixtures: Record<string, any>[] = [
verified: true,
turbo: false,
hibernated: false,
domain: 'test.com',
settings: { network: 1 },
created: Math.floor(Date.now() / 1e3),
updated: Math.floor(Date.now() / 1e3)
Expand All @@ -18,6 +19,7 @@ const fixtures: Record<string, any>[] = [
turbo: false,
hibernated: false,
deleted: true,
domain: 'test1.com',
settings: { network: 1 },
created: Math.floor(Date.now() / 1e3),
updated: Math.floor(Date.now() / 1e3)
Expand Down

0 comments on commit e046e4e

Please sign in to comment.