Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show creator + badge on user profile (#597)
- Loading branch information
Showing
11 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sigle/app': minor | ||
--- | ||
|
||
Display The Explorer Guild creator + badge on the profile page of a user. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { FastifyInstance } from 'fastify'; | ||
import { TestBaseDB, TestDBUser } from '../../../jest/db'; | ||
import { prisma } from '../../../prisma'; | ||
import { redis } from '../../../redis'; | ||
import { buildFastifyServer } from '../../../server'; | ||
|
||
let server: FastifyInstance; | ||
|
||
beforeAll(() => { | ||
server = buildFastifyServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await TestBaseDB.cleanup(); | ||
await redis.quit(); | ||
await prisma.$disconnect(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await prisma.user.deleteMany({}); | ||
await prisma.subscription.deleteMany({}); | ||
}); | ||
|
||
it('Should return public user without subscription', async () => { | ||
const stacksAddress = 'SP3VCX5NFQ8VCHFS9M6N40ZJNVTRT4HZ62WFH5C4Q'; | ||
const user = await TestDBUser.seedUser({ | ||
stacksAddress, | ||
}); | ||
|
||
const response = await server.inject({ | ||
method: 'GET', | ||
url: `/api/users/${stacksAddress}`, | ||
}); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.json()).toEqual({ id: user.id, stacksAddress }); | ||
}); | ||
|
||
it('Should return public user with subscription', async () => { | ||
const stacksAddress = 'SP3VCX5NFQ8VCHFS9M6N40ZJNVTRT4HZ62WFH5C4Q'; | ||
const user = await TestDBUser.seedUserWithSubscription({ | ||
stacksAddress, | ||
}); | ||
|
||
const response = await server.inject({ | ||
method: 'GET', | ||
url: `/api/users/${stacksAddress}`, | ||
}); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.json()).toEqual({ | ||
id: user.id, | ||
stacksAddress, | ||
subscription: { | ||
id: expect.any(String), | ||
nftId: expect.any(Number), | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { FastifyInstance } from 'fastify'; | ||
import { prisma } from '../../../prisma'; | ||
|
||
type GetUserByAddressResponse = { | ||
id: string; | ||
stacksAddress: string; | ||
subscription?: { | ||
id: string; | ||
nftId: number; | ||
}; | ||
} | null; | ||
const getUserByAddressResponseSchema = { | ||
type: 'object', | ||
nullable: true, | ||
properties: { | ||
id: { type: 'string' }, | ||
stacksAddress: { type: 'string' }, | ||
subscription: { | ||
type: 'object', | ||
nullable: true, | ||
properties: { | ||
id: { type: 'string' }, | ||
nftId: { type: 'number' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export async function createGetUserByAddressEndpoint(fastify: FastifyInstance) { | ||
return fastify.get<{ | ||
Reply: GetUserByAddressResponse; | ||
Params: { userAddress: string }; | ||
}>( | ||
'/api/users/:userAddress', | ||
{ | ||
schema: { | ||
response: { | ||
200: getUserByAddressResponseSchema, | ||
}, | ||
}, | ||
}, | ||
async (req, res) => { | ||
const { userAddress } = req.params; | ||
|
||
const user = await prisma.user.findUnique({ | ||
where: { stacksAddress: userAddress }, | ||
select: { | ||
id: true, | ||
stacksAddress: true, | ||
subscriptions: { | ||
select: { | ||
id: true, | ||
nftId: true, | ||
}, | ||
where: { | ||
status: 'ACTIVE', | ||
}, | ||
take: 1, | ||
}, | ||
}, | ||
}); | ||
|
||
return res.send( | ||
user | ||
? { | ||
id: user.id, | ||
stacksAddress: user.stacksAddress, | ||
subscription: user.subscriptions[0], | ||
} | ||
: null | ||
); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters