Skip to content

Commit

Permalink
Removed snake_keys from note-settings storage
Browse files Browse the repository at this point in the history
  • Loading branch information
slaveeks committed Oct 21, 2023
1 parent c37222a commit fc71bfc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/presentation/http/router/noteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface NoteListRouterOptions {
* @param done - callback
*/
const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, opts, done) => {

const noteListService = opts.noteListService;

/**
Expand All @@ -41,4 +40,5 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, o

done();
};

export default NoteListRouter;
3 changes: 1 addition & 2 deletions src/presentation/http/router/noteSettings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { FastifyPluginCallback } from 'fastify';
import type NoteSettingsService from '@domain/service/noteSettings.js';
import type { NoteInternalId } from '@domain/entities/note.js';
import type NoteSettings from '@domain/entities/noteSettings.js';
import notEmpty from '@infrastructure/utils/notEmpty.js';
import useNoteResolver from '../middlewares/note/useNoteResolver.js';
import type NoteService from '@domain/service/note.js';
import { NotePublicId } from '@domain/entities/note.js';
import type { NotePublicId } from '@domain/entities/note.js';

/**
* Interface for the note settings router.
Expand Down
57 changes: 14 additions & 43 deletions src/repository/storage/postgres/orm/sequelize/noteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { NoteModel } from '@repository/storage/postgres/orm/sequelize/note.js';
import type NoteSettings from '@domain/entities/noteSettings.js';
import type { NoteSettingsCreationAttributes } from '@domain/entities/noteSettings.js';

/* eslint-disable @typescript-eslint/naming-convention */

/**
* Class representing a notes settings model in database
*/
Expand All @@ -19,17 +17,17 @@ export class NoteSettingsModel extends Model<InferAttributes<NoteSettingsModel>,
/**
* Note ID
*/
public declare note_id: NoteSettings['noteId'];
public declare noteId: NoteSettings['noteId'];

/**
* Custom hostname
*/
public declare custom_hostname: CreationOptional<NoteSettings['customHostname']>;
public declare customHostname: CreationOptional<NoteSettings['customHostname']>;

/**
* Is note public
*/
public declare is_public: CreationOptional<NoteSettings['isPublic']>;
public declare isPublic: CreationOptional<NoteSettings['isPublic']>;
}

/**
Expand Down Expand Up @@ -73,19 +71,19 @@ export default class NoteSettingsSequelizeStorage {
autoIncrement: true,
primaryKey: true,
},
note_id: {
noteId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: NoteModel.tableName,
key: 'id',
},
},
custom_hostname: {
customHostname: {
type: DataTypes.STRING,
allowNull: true,
},
is_public: {
isPublic: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
Expand Down Expand Up @@ -118,12 +116,7 @@ export default class NoteSettingsSequelizeStorage {
return null;
}

return {
id: noteSettings.id,
noteId: noteSettings.note_id,
isPublic: noteSettings.is_public,
customHostname: noteSettings.custom_hostname,
};
return noteSettings;
}

/**
Expand All @@ -135,7 +128,7 @@ export default class NoteSettingsSequelizeStorage {
public async getNoteSettingsByNoteId(noteId: NoteSettings['noteId']): Promise<NoteSettings> {
const settings = await this.model.findOne({
where: {
note_id: noteId,
noteId: noteId,
},
});

Expand All @@ -146,12 +139,7 @@ export default class NoteSettingsSequelizeStorage {
throw new Error('Note settings not found');
}

return {
id: settings.id,
noteId: settings.note_id,
customHostname: settings.custom_hostname,
isPublic: settings.is_public,
};
return settings;
}

/**
Expand Down Expand Up @@ -185,17 +173,12 @@ export default class NoteSettingsSequelizeStorage {
}: NoteSettingsCreationAttributes
): Promise<NoteSettings> {
const settings = await this.model.create({
note_id: noteId,
custom_hostname: customHostname,
is_public: isPublic,
noteId,
customHostname,
isPublic,
});

return {
id: settings.id,
noteId: settings.note_id,
customHostname: settings.custom_hostname,
isPublic: settings.is_public,
};
return settings;
}

/**
Expand All @@ -214,18 +197,6 @@ export default class NoteSettingsSequelizeStorage {
return null;
}

const values = {
enabled: data.isPublic,
custom_hostname: data.customHostname,
};

const updatedSettings = await settingsToUpdate.update(values);

return {
id: updatedSettings.id,
noteId: updatedSettings.note_id,
customHostname: updatedSettings.custom_hostname,
isPublic: updatedSettings.is_public,
};
return await settingsToUpdate.update(data);
}
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5999,11 +5999,11 @@ __metadata:

"typescript@patch:typescript@^5.0.4#~builtin<compat/typescript>":
version: 5.2.2
resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin<compat/typescript>::version=5.2.2&hash=f3b441"
resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin<compat/typescript>::version=5.2.2&hash=ad5954"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 0f4da2f15e6f1245e49db15801dbee52f2bbfb267e1c39225afdab5afee1a72839cd86000e65ee9d7e4dfaff12239d28beaf5ee431357fcced15fb08583d72ca
checksum: 07106822b4305de3f22835cbba949a2b35451cad50888759b6818421290ff95d522b38ef7919e70fb381c5fe9c1c643d7dea22c8b31652a717ddbd57b7f4d554
languageName: node
linkType: hard

Expand Down

0 comments on commit fc71bfc

Please sign in to comment.