forked from cerc-io/snowballtools-base
Add createdBy
column in deployments table (#51)
* Add and use createdBy field in deployment entity * Use updated get deployments client method in UI --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
d97794f1bf
commit
8bbe2583cb
@ -118,12 +118,16 @@ export class Database {
|
||||
const deployments = await deploymentRepository.find({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true
|
||||
domain: true,
|
||||
createdBy: true
|
||||
},
|
||||
where: {
|
||||
project: {
|
||||
id: projectId
|
||||
}
|
||||
},
|
||||
order: {
|
||||
createdAt: 'DESC'
|
||||
}
|
||||
});
|
||||
|
||||
@ -262,12 +266,13 @@ export class Database {
|
||||
}
|
||||
}
|
||||
|
||||
async redeployToProdById (deploymentId: string): Promise<Deployment> {
|
||||
async redeployToProdById (userId: string, deploymentId: string): Promise<Deployment> {
|
||||
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
||||
const deployment = await deploymentRepository.findOne({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true
|
||||
domain: true,
|
||||
createdBy: true
|
||||
},
|
||||
where: {
|
||||
id: Number(deploymentId)
|
||||
@ -282,6 +287,9 @@ export class Database {
|
||||
if (updatedDeployment.environment === Environment.Production) {
|
||||
// TODO: Put isCurrent field in project
|
||||
updatedDeployment.isCurrent = true;
|
||||
updatedDeployment.createdBy = Object.assign(new User(), {
|
||||
id: Number(userId)
|
||||
});
|
||||
}
|
||||
|
||||
await deploymentRepository.update({ id: Number(deploymentId) }, { domain: null, isCurrent: false });
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
|
||||
import { Project } from './Project';
|
||||
import { Domain } from './Domain';
|
||||
import { User } from './User';
|
||||
|
||||
export enum Environment {
|
||||
Production = 'Production',
|
||||
@ -59,6 +60,10 @@ export class Deployment {
|
||||
})
|
||||
status!: Status;
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'createdBy' })
|
||||
createdBy!: User;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
|
||||
|
@ -162,9 +162,9 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
||||
}
|
||||
},
|
||||
|
||||
redeployToProd: async (_: any, { deploymentId }: { deploymentId: string }) => {
|
||||
redeployToProd: async (_: any, { deploymentId }: { deploymentId: string }, context: any) => {
|
||||
try {
|
||||
await db.redeployToProdById(deploymentId);
|
||||
await db.redeployToProdById(context.userId, deploymentId);
|
||||
return true;
|
||||
} catch (err) {
|
||||
log(err);
|
||||
|
@ -91,6 +91,7 @@ type Deployment {
|
||||
status: DeploymentStatus!
|
||||
createdAt: String!
|
||||
updatedAt: String!
|
||||
createdBy: User!
|
||||
}
|
||||
|
||||
type Domain {
|
||||
|
@ -55,6 +55,7 @@ export const deploymentToGqlType = (dbDeployment: Deployment): any => {
|
||||
environment: dbDeployment.environment,
|
||||
isCurrent: dbDeployment.isCurrent,
|
||||
status: dbDeployment.status,
|
||||
createdBy: dbDeployment.createdBy,
|
||||
createdAt: dbDeployment.createdAt,
|
||||
updatedAt: dbDeployment.updatedAt
|
||||
};
|
||||
|
10
packages/backend/test/fixtures/deployments.json
vendored
10
packages/backend/test/fixtures/deployments.json
vendored
@ -2,6 +2,7 @@
|
||||
{
|
||||
"projectIndex": 0,
|
||||
"domainIndex":0,
|
||||
"createdByIndex": 0,
|
||||
"title": "nextjs-boilerplate-1",
|
||||
"status": "Building",
|
||||
"environment": "Production",
|
||||
@ -12,6 +13,7 @@
|
||||
{
|
||||
"projectIndex": 0,
|
||||
"domainIndex":1,
|
||||
"createdByIndex": 0,
|
||||
"title": "nextjs-boilerplate-2",
|
||||
"status": "Ready",
|
||||
"environment": "Preview",
|
||||
@ -22,6 +24,7 @@
|
||||
{
|
||||
"projectIndex": 0,
|
||||
"domainIndex":2,
|
||||
"createdByIndex": 0,
|
||||
"title": "nextjs-boilerplate-3",
|
||||
"status": "Error",
|
||||
"environment": "Development",
|
||||
@ -32,6 +35,7 @@
|
||||
{
|
||||
"projectIndex": 0,
|
||||
"domainIndex": null,
|
||||
"createdByIndex": 0,
|
||||
"title": "nextjs-boilerplate-4",
|
||||
"status": "Ready",
|
||||
"environment": "Production",
|
||||
@ -42,6 +46,7 @@
|
||||
{
|
||||
"projectIndex": 1,
|
||||
"domainIndex":3,
|
||||
"createdByIndex": 1,
|
||||
"title": "nextjs-boilerplate-1",
|
||||
"status": "Building",
|
||||
"environment": "Production",
|
||||
@ -52,6 +57,7 @@
|
||||
{
|
||||
"projectIndex": 1,
|
||||
"domainIndex":4,
|
||||
"createdByIndex": 1,
|
||||
"title": "nextjs-boilerplate-2",
|
||||
"status": "Ready",
|
||||
"environment": "Preview",
|
||||
@ -62,6 +68,7 @@
|
||||
{
|
||||
"projectIndex": 1,
|
||||
"domainIndex":5,
|
||||
"createdByIndex": 1,
|
||||
"title": "nextjs-boilerplate-3",
|
||||
"status": "Error",
|
||||
"environment": "Development",
|
||||
@ -72,6 +79,7 @@
|
||||
{
|
||||
"projectIndex": 2,
|
||||
"domainIndex":6,
|
||||
"createdByIndex": 2,
|
||||
"title": "nextjs-boilerplate-1",
|
||||
"status": "Building",
|
||||
"environment": "Production",
|
||||
@ -82,6 +90,7 @@
|
||||
{
|
||||
"projectIndex": 2,
|
||||
"domainIndex":7,
|
||||
"createdByIndex": 2,
|
||||
"title": "nextjs-boilerplate-2",
|
||||
"status": "Ready",
|
||||
"environment": "Preview",
|
||||
@ -92,6 +101,7 @@
|
||||
{
|
||||
"projectIndex": 2,
|
||||
"domainIndex":8,
|
||||
"createdByIndex": 2,
|
||||
"title": "nextjs-boilerplate-3",
|
||||
"status": "Error",
|
||||
"environment": "Development",
|
||||
|
@ -86,7 +86,8 @@ const generateTestData = async (dataSource: DataSource) => {
|
||||
|
||||
const deploymentRelations = {
|
||||
project: savedProjects,
|
||||
domain: savedDomains
|
||||
domain: savedDomains,
|
||||
createdBy: savedUsers
|
||||
};
|
||||
|
||||
await loadAndSaveData(Deployment, dataSource, path.resolve(__dirname, DEPLOYMENT_DATA_PATH), deploymentRelations);
|
||||
|
@ -102,7 +102,7 @@ const DeploymentDetailsCard = ({
|
||||
</div>
|
||||
<div className="col-span-1 flex items-center">
|
||||
<Typography color="gray" className="grow">
|
||||
{relativeTimeMs(deployment.createdAt)} ^ {deployment.author}
|
||||
{relativeTimeMs(deployment.createdAt)} ^ {deployment.createdBy.name}
|
||||
</Typography>
|
||||
<Menu placement="bottom-start">
|
||||
<MenuHandler>
|
||||
|
@ -158,6 +158,11 @@ query ($projectId: String!) {
|
||||
status
|
||||
createdAt
|
||||
updatedAt
|
||||
createdBy {
|
||||
id
|
||||
name
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
@ -47,6 +47,14 @@ export type Domain = {
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export type User = {
|
||||
id: string
|
||||
name: string
|
||||
email: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export type Deployment = {
|
||||
id: string
|
||||
domain: Domain
|
||||
@ -56,14 +64,7 @@ export type Deployment = {
|
||||
environment: Environment
|
||||
isCurrent: boolean
|
||||
status: DeploymentStatus
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export type User = {
|
||||
id: string
|
||||
name: string
|
||||
email: string
|
||||
createdBy: User
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user