Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't clean up settings when optional data is not present #5118

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/lib/db/project-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IEnvironment,
IFlagResolver,
IProject,
IProjectUpdate,
IProjectWithCount,
ProjectMode,
} from '../types';
Expand Down Expand Up @@ -259,25 +260,30 @@ class ProjectStore implements IProjectStore {
return present;
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
async update(data): Promise<void> {
async update(data: IProjectUpdate): Promise<void> {
try {
await this.db(TABLE)
.where({ id: data.id })
.update(this.fieldToRow(data));
if (await this.hasProjectSettings(data.id)) {
await this.db(SETTINGS_TABLE)
.where({ project: data.id })
.update({
if (
data.defaultStickiness !== undefined ||
data.featureLimit !== undefined
) {
if (await this.hasProjectSettings(data.id)) {
await this.db(SETTINGS_TABLE)
.where({ project: data.id })
.update({
default_stickiness: data.defaultStickiness,
feature_limit: data.featureLimit,
});
} else {
// What happens with project mode in this case?
await this.db(SETTINGS_TABLE).insert({
project: data.id,
default_stickiness: data.defaultStickiness,
feature_limit: data.featureLimit,
});
} else {
await this.db(SETTINGS_TABLE).insert({
project: data.id,
default_stickiness: data.defaultStickiness,
feature_limit: data.featureLimit,
});
}
}
} catch (err) {
this.logger.error('Could not update project, error: ', err);
Expand Down
11 changes: 9 additions & 2 deletions src/lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
ProjectAccessUserRolesDeleted,
IFeatureNaming,
CreateProject,
IProjectUpdate,
} from '../types';
import {
IProjectQuery,
Expand Down Expand Up @@ -259,16 +260,22 @@ export default class ProjectService {
return data;
}

async updateProject(updatedProject: IProject, user: IUser): Promise<void> {
async updateProject(
updatedProject: IProjectUpdate,
user: IUser,
): Promise<void> {
const preData = await this.projectStore.get(updatedProject.id);

await this.projectStore.update(updatedProject);

// updated project contains instructions to update the project but it may not represent a whole project
const afterData = await this.projectStore.get(updatedProject.id);
Comment on lines +271 to +272
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, our diff is a bit misleading:
image (24)


await this.eventStore.store({
type: PROJECT_UPDATED,
project: updatedProject.id,
createdBy: getCreatedBy(user),
data: updatedProject,
data: afterData,
preData,
});
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,16 @@ export interface IProject {
featureNaming?: IFeatureNaming;
}

// mimics UpdateProjectSchema
export interface IProjectUpdate {
id: string;
name: string;
description?: string;
mode?: ProjectMode;
defaultStickiness?: string;
featureLimit?: number;
}

/**
* Extends IRole making description mandatory
*/
Expand Down
Loading