Add method to fetch DNS data for latest deployment

This commit is contained in:
IshaVenikar 2025-01-30 15:18:28 +05:30
parent b5762432e6
commit 56eccb48b3
7 changed files with 75 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import { Domain } from './entity/Domain';
import { getEntities, loadAndSaveData } from './utils';
import { UserOrganization } from './entity/UserOrganization';
import { Deployer } from './entity/Deployer';
import { DNSRecordAttributes } from './types';
const ORGANIZATION_DATA_PATH = '../test/fixtures/organizations.json';
@ -602,6 +603,28 @@ export class Database {
return domains;
}
async getLatestDNSDataByProjectId(
projectId: string,
): Promise<DNSRecordAttributes | null> {
const deploymentRepository = this.dataSource.getRepository(Deployment);
const deployment = await deploymentRepository.findOne({
where: {
project: {
id: projectId
},
}, order: {
createdAt: "DESC",
},
});
if (deployment === null) {
throw new Error(`Error finding DNS data for project with id ${projectId}`);
}
return deployment.dnsRecordData;
}
async addDeployer(data: DeepPartial<Deployer>): Promise<Deployer> {
const deployerRepository = this.dataSource.getRepository(Deployer);
const newDomain = await deployerRepository.save(data);

View File

@ -95,6 +95,13 @@ export const createResolvers = async (service: Service): Promise<any> => {
) => {
return service.verifyTx(txHash, amount, senderAddress);
},
getLatestDNSDataByProjectId: async (
_: any,
{ projectId }: { projectId: string },
) => {
return service.getLatestDNSDataByProjectId(projectId);
},
},
// TODO: Return error in GQL response

View File

@ -249,6 +249,14 @@ type Auction {
bids: [Bid!]!
}
type DNSRecordAttributes {
name: string;
value: string;
request: string;
resourceType: string;
version: string;
}
input AuctionParams {
maxPrice: String,
numProviders: Int,
@ -265,6 +273,7 @@ type Query {
projectMembers(projectId: String!): [ProjectMember!]
searchProjects(searchText: String!): [Project!]
getAuctionData(auctionId: String!): Auction!
getLatestDNSDataByProjectId(projectId: String!): DNSRecordAttributes
domains(projectId: String!, filter: FilterDomainsInput): [Domain]
deployers: [Deployer]
address: String!

View File

@ -447,6 +447,11 @@ export class Service {
return dbDeployments;
}
async getLatestDNSDataByProjectId(projectId: string): Promise<DNSRecordAttributes | null> {
const dbDeployments = await this.db.getLatestDNSDataByProjectId(projectId);
return dbDeployments;
}
async getEnvironmentVariablesByProjectId(
projectId: string,
): Promise<EnvironmentVariable[]> {

View File

@ -453,4 +453,15 @@ export class GQLClient {
return data.verifyTx;
}
async getLatestDNSDataByProjectId(projectId: string): Promise<types.DNSRecordAttributes> {
const { data } = await this.client.query({
query: queries.getLatestDNSDataByProjectId,
variables: {
projectId,
},
});
return data.dnsRecordData;
}
}

View File

@ -343,3 +343,15 @@ query ($txHash: String!, $amount: String!, $senderAddress: String!) {
verifyTx(txHash: $txHash, amount: $amount, senderAddress: $senderAddress)
}
`;
export const getLatestDNSDataByProjectId = gql`
query($projectId: String!) {
dnsRecordData(projectId: $projectId) {
name
value
request
resourceType
version
}
}
`;

View File

@ -376,3 +376,11 @@ export type AuctionParams = {
maxPrice: string;
numProviders: number;
};
export type DNSRecordAttributes = {
name: string;
value: string;
request: string;
resourceType: string;
version: string;
}