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
@ -28,12 +28,12 @@ export class Database {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async init () : Promise<void> {
|
async init (): Promise<void> {
|
||||||
await this.dataSource.initialize();
|
await this.dataSource.initialize();
|
||||||
log('database initialized');
|
log('database initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUser (userId: number) : Promise<User | null> {
|
async getUser (userId: number): Promise<User | null> {
|
||||||
const userRepository = this.dataSource.getRepository(User);
|
const userRepository = this.dataSource.getRepository(User);
|
||||||
const user = await userRepository.findOneBy({
|
const user = await userRepository.findOneBy({
|
||||||
id: userId
|
id: userId
|
||||||
@ -42,7 +42,7 @@ export class Database {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOrganizationsByUserId (userId: number) : Promise<Organization[]> {
|
async getOrganizationsByUserId (userId: number): Promise<Organization[]> {
|
||||||
const userOrganizationRepository = this.dataSource.getRepository(UserOrganization);
|
const userOrganizationRepository = this.dataSource.getRepository(UserOrganization);
|
||||||
|
|
||||||
const userOrgs = await userOrganizationRepository.find({
|
const userOrgs = await userOrganizationRepository.find({
|
||||||
@ -118,12 +118,16 @@ export class Database {
|
|||||||
const deployments = await deploymentRepository.find({
|
const deployments = await deploymentRepository.find({
|
||||||
relations: {
|
relations: {
|
||||||
project: true,
|
project: true,
|
||||||
domain: true
|
domain: true,
|
||||||
|
createdBy: true
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
project: {
|
project: {
|
||||||
id: projectId
|
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 deploymentRepository = this.dataSource.getRepository(Deployment);
|
||||||
const deployment = await deploymentRepository.findOne({
|
const deployment = await deploymentRepository.findOne({
|
||||||
relations: {
|
relations: {
|
||||||
project: true,
|
project: true,
|
||||||
domain: true
|
domain: true,
|
||||||
|
createdBy: true
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
id: Number(deploymentId)
|
id: Number(deploymentId)
|
||||||
@ -282,6 +287,9 @@ export class Database {
|
|||||||
if (updatedDeployment.environment === Environment.Production) {
|
if (updatedDeployment.environment === Environment.Production) {
|
||||||
// TODO: Put isCurrent field in project
|
// TODO: Put isCurrent field in project
|
||||||
updatedDeployment.isCurrent = true;
|
updatedDeployment.isCurrent = true;
|
||||||
|
updatedDeployment.createdBy = Object.assign(new User(), {
|
||||||
|
id: Number(userId)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await deploymentRepository.update({ id: Number(deploymentId) }, { domain: null, isCurrent: false });
|
await deploymentRepository.update({ id: Number(deploymentId) }, { domain: null, isCurrent: false });
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
|
|
||||||
import { Project } from './Project';
|
import { Project } from './Project';
|
||||||
import { Domain } from './Domain';
|
import { Domain } from './Domain';
|
||||||
|
import { User } from './User';
|
||||||
|
|
||||||
export enum Environment {
|
export enum Environment {
|
||||||
Production = 'Production',
|
Production = 'Production',
|
||||||
@ -59,6 +60,10 @@ export class Deployment {
|
|||||||
})
|
})
|
||||||
status!: Status;
|
status!: Status;
|
||||||
|
|
||||||
|
@ManyToOne(() => User)
|
||||||
|
@JoinColumn({ name: 'createdBy' })
|
||||||
|
createdBy!: User;
|
||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
createdAt!: Date;
|
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 {
|
try {
|
||||||
await db.redeployToProdById(deploymentId);
|
await db.redeployToProdById(context.userId, deploymentId);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log(err);
|
log(err);
|
||||||
|
@ -91,6 +91,7 @@ type Deployment {
|
|||||||
status: DeploymentStatus!
|
status: DeploymentStatus!
|
||||||
createdAt: String!
|
createdAt: String!
|
||||||
updatedAt: String!
|
updatedAt: String!
|
||||||
|
createdBy: User!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Domain {
|
type Domain {
|
||||||
|
@ -55,6 +55,7 @@ export const deploymentToGqlType = (dbDeployment: Deployment): any => {
|
|||||||
environment: dbDeployment.environment,
|
environment: dbDeployment.environment,
|
||||||
isCurrent: dbDeployment.isCurrent,
|
isCurrent: dbDeployment.isCurrent,
|
||||||
status: dbDeployment.status,
|
status: dbDeployment.status,
|
||||||
|
createdBy: dbDeployment.createdBy,
|
||||||
createdAt: dbDeployment.createdAt,
|
createdAt: dbDeployment.createdAt,
|
||||||
updatedAt: dbDeployment.updatedAt
|
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,
|
"projectIndex": 0,
|
||||||
"domainIndex":0,
|
"domainIndex":0,
|
||||||
|
"createdByIndex": 0,
|
||||||
"title": "nextjs-boilerplate-1",
|
"title": "nextjs-boilerplate-1",
|
||||||
"status": "Building",
|
"status": "Building",
|
||||||
"environment": "Production",
|
"environment": "Production",
|
||||||
@ -12,6 +13,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 0,
|
"projectIndex": 0,
|
||||||
"domainIndex":1,
|
"domainIndex":1,
|
||||||
|
"createdByIndex": 0,
|
||||||
"title": "nextjs-boilerplate-2",
|
"title": "nextjs-boilerplate-2",
|
||||||
"status": "Ready",
|
"status": "Ready",
|
||||||
"environment": "Preview",
|
"environment": "Preview",
|
||||||
@ -22,6 +24,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 0,
|
"projectIndex": 0,
|
||||||
"domainIndex":2,
|
"domainIndex":2,
|
||||||
|
"createdByIndex": 0,
|
||||||
"title": "nextjs-boilerplate-3",
|
"title": "nextjs-boilerplate-3",
|
||||||
"status": "Error",
|
"status": "Error",
|
||||||
"environment": "Development",
|
"environment": "Development",
|
||||||
@ -32,6 +35,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 0,
|
"projectIndex": 0,
|
||||||
"domainIndex": null,
|
"domainIndex": null,
|
||||||
|
"createdByIndex": 0,
|
||||||
"title": "nextjs-boilerplate-4",
|
"title": "nextjs-boilerplate-4",
|
||||||
"status": "Ready",
|
"status": "Ready",
|
||||||
"environment": "Production",
|
"environment": "Production",
|
||||||
@ -42,6 +46,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 1,
|
"projectIndex": 1,
|
||||||
"domainIndex":3,
|
"domainIndex":3,
|
||||||
|
"createdByIndex": 1,
|
||||||
"title": "nextjs-boilerplate-1",
|
"title": "nextjs-boilerplate-1",
|
||||||
"status": "Building",
|
"status": "Building",
|
||||||
"environment": "Production",
|
"environment": "Production",
|
||||||
@ -52,6 +57,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 1,
|
"projectIndex": 1,
|
||||||
"domainIndex":4,
|
"domainIndex":4,
|
||||||
|
"createdByIndex": 1,
|
||||||
"title": "nextjs-boilerplate-2",
|
"title": "nextjs-boilerplate-2",
|
||||||
"status": "Ready",
|
"status": "Ready",
|
||||||
"environment": "Preview",
|
"environment": "Preview",
|
||||||
@ -62,6 +68,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 1,
|
"projectIndex": 1,
|
||||||
"domainIndex":5,
|
"domainIndex":5,
|
||||||
|
"createdByIndex": 1,
|
||||||
"title": "nextjs-boilerplate-3",
|
"title": "nextjs-boilerplate-3",
|
||||||
"status": "Error",
|
"status": "Error",
|
||||||
"environment": "Development",
|
"environment": "Development",
|
||||||
@ -72,6 +79,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 2,
|
"projectIndex": 2,
|
||||||
"domainIndex":6,
|
"domainIndex":6,
|
||||||
|
"createdByIndex": 2,
|
||||||
"title": "nextjs-boilerplate-1",
|
"title": "nextjs-boilerplate-1",
|
||||||
"status": "Building",
|
"status": "Building",
|
||||||
"environment": "Production",
|
"environment": "Production",
|
||||||
@ -82,6 +90,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 2,
|
"projectIndex": 2,
|
||||||
"domainIndex":7,
|
"domainIndex":7,
|
||||||
|
"createdByIndex": 2,
|
||||||
"title": "nextjs-boilerplate-2",
|
"title": "nextjs-boilerplate-2",
|
||||||
"status": "Ready",
|
"status": "Ready",
|
||||||
"environment": "Preview",
|
"environment": "Preview",
|
||||||
@ -92,6 +101,7 @@
|
|||||||
{
|
{
|
||||||
"projectIndex": 2,
|
"projectIndex": 2,
|
||||||
"domainIndex":8,
|
"domainIndex":8,
|
||||||
|
"createdByIndex": 2,
|
||||||
"title": "nextjs-boilerplate-3",
|
"title": "nextjs-boilerplate-3",
|
||||||
"status": "Error",
|
"status": "Error",
|
||||||
"environment": "Development",
|
"environment": "Development",
|
||||||
|
@ -86,7 +86,8 @@ const generateTestData = async (dataSource: DataSource) => {
|
|||||||
|
|
||||||
const deploymentRelations = {
|
const deploymentRelations = {
|
||||||
project: savedProjects,
|
project: savedProjects,
|
||||||
domain: savedDomains
|
domain: savedDomains,
|
||||||
|
createdBy: savedUsers
|
||||||
};
|
};
|
||||||
|
|
||||||
await loadAndSaveData(Deployment, dataSource, path.resolve(__dirname, DEPLOYMENT_DATA_PATH), deploymentRelations);
|
await loadAndSaveData(Deployment, dataSource, path.resolve(__dirname, DEPLOYMENT_DATA_PATH), deploymentRelations);
|
||||||
|
@ -102,7 +102,7 @@ const DeploymentDetailsCard = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="col-span-1 flex items-center">
|
<div className="col-span-1 flex items-center">
|
||||||
<Typography color="gray" className="grow">
|
<Typography color="gray" className="grow">
|
||||||
{relativeTimeMs(deployment.createdAt)} ^ {deployment.author}
|
{relativeTimeMs(deployment.createdAt)} ^ {deployment.createdBy.name}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Menu placement="bottom-start">
|
<Menu placement="bottom-start">
|
||||||
<MenuHandler>
|
<MenuHandler>
|
||||||
|
@ -158,6 +158,11 @@ query ($projectId: String!) {
|
|||||||
status
|
status
|
||||||
createdAt
|
createdAt
|
||||||
updatedAt
|
updatedAt
|
||||||
|
createdBy {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
email
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@ -47,6 +47,14 @@ export type Domain = {
|
|||||||
updatedAt: string
|
updatedAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type User = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
email: string
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
export type Deployment = {
|
export type Deployment = {
|
||||||
id: string
|
id: string
|
||||||
domain: Domain
|
domain: Domain
|
||||||
@ -56,14 +64,7 @@ export type Deployment = {
|
|||||||
environment: Environment
|
environment: Environment
|
||||||
isCurrent: boolean
|
isCurrent: boolean
|
||||||
status: DeploymentStatus
|
status: DeploymentStatus
|
||||||
createdAt: string
|
createdBy: User
|
||||||
updatedAt: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type User = {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
email: string
|
|
||||||
createdAt: string
|
createdAt: string
|
||||||
updatedAt: string
|
updatedAt: string
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user