From 18075324fe0dc2a763e3920c9cc3f51c31d463c0 Mon Sep 17 00:00:00 2001 From: GitHub Release <> Date: Fri, 24 Nov 2023 08:53:31 +0000 Subject: [PATCH 1/5] Bump version to 0.115.0 [release] --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e57686ad..e1812fb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@datalens-tech/datalens-us", - "version": "0.0.0", + "version": "0.115.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@datalens-tech/datalens-us", - "version": "0.0.0", + "version": "0.115.0", "license": "Apache-2.0", "dependencies": { "@gravity-ui/expresskit": "^1.0.0", diff --git a/package.json b/package.json index f21b2887..5db4901a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@datalens-tech/datalens-us", "description": "United Storage", - "version": "0.0.0", + "version": "0.115.0", "private": true, "author": "DataLens Team ", "license": "Apache-2.0", From d6724bbf95ebfaa42f8fca64fd4d09aeef75e8e1 Mon Sep 17 00:00:00 2001 From: Stanislav Kiselev <“staskis@yandex-team.ru”> Date: Mon, 4 Dec 2023 19:34:51 +0300 Subject: [PATCH 2/5] Migration file which adds alias column to favorites table --- ...0231204125203_add_alias_column_to_favorites.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/db/migrations/20231204125203_add_alias_column_to_favorites.ts diff --git a/src/db/migrations/20231204125203_add_alias_column_to_favorites.ts b/src/db/migrations/20231204125203_add_alias_column_to_favorites.ts new file mode 100644 index 00000000..39db34c5 --- /dev/null +++ b/src/db/migrations/20231204125203_add_alias_column_to_favorites.ts @@ -0,0 +1,15 @@ +import type {Knex} from 'knex'; + +export async function up(knex: Knex): Promise { + return knex.raw(` + ALTER TABLE favorites + ADD COLUMN alias TEXT; + `); +} + +export async function down(knex: Knex): Promise { + return knex.raw(` + ALTER TABLE favorites + DROP COLUMN alias; + `); +} From 4669550c46b5686058386b2c0e2acaf7e8f6d225 Mon Sep 17 00:00:00 2001 From: Stanislav Kiselev <“staskis@yandex-team.ru”> Date: Mon, 4 Dec 2023 19:49:47 +0300 Subject: [PATCH 3/5] Update package versions --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e1812fb7..e57686ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@datalens-tech/datalens-us", - "version": "0.115.0", + "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@datalens-tech/datalens-us", - "version": "0.115.0", + "version": "0.0.0", "license": "Apache-2.0", "dependencies": { "@gravity-ui/expresskit": "^1.0.0", diff --git a/package.json b/package.json index 5db4901a..f21b2887 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@datalens-tech/datalens-us", "description": "United Storage", - "version": "0.115.0", + "version": "0.0.0", "private": true, "author": "DataLens Team ", "license": "Apache-2.0", From e449df2667034ea1e0b17ee1d1c467c31cbae8ef Mon Sep 17 00:00:00 2001 From: Stanislav Kiselev <“staskis@yandex-team.ru”> Date: Wed, 6 Dec 2023 20:52:50 +0300 Subject: [PATCH 4/5] Added renameFavorite method which updates alias column in favorites table --- src/const/common.ts | 1 + src/controllers/favorites.ts | 13 +++++++++++ src/db/models/favorite/index.ts | 36 +++++++++++++++++++++++++++++- src/db/models/favorite/scheme.ts | 15 ++++++++++++- src/routes.ts | 5 +++++ src/services/favorite.service.ts | 14 ++++++++++++ src/types/models/favorite.ts | 6 +++++ src/types/models/tables-columns.ts | 1 + src/types/services.types.ts | 4 ++++ 9 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/const/common.ts b/src/const/common.ts index 20a3510c..14ea7491 100644 --- a/src/const/common.ts +++ b/src/const/common.ts @@ -84,6 +84,7 @@ export const RETURN_NAVIGATION_COLUMNS = [ ]; export const RETURN_FAVORITES_COLUMNS = [ + 'favorites.alias', 'entries.entryId', 'entries.scope', 'entries.type', diff --git a/src/controllers/favorites.ts b/src/controllers/favorites.ts index 365ef511..d6fb346a 100644 --- a/src/controllers/favorites.ts +++ b/src/controllers/favorites.ts @@ -62,6 +62,19 @@ export default { const {code, response} = prepareResponse({data: result}); + res.status(code).send(response); + }, + renameFavorite: async (req: Request, res: Response) => { + const {params, body} = req; + + const result = await FavoriteService.rename({ + entryId: params.entryId, + name: body.name, + ctx: req.ctx, + }); + + const {code, response} = prepareResponse({data: result}); + res.status(code).send(response); }, }; diff --git a/src/db/models/favorite/index.ts b/src/db/models/favorite/index.ts index a1dff773..7c1c29be 100644 --- a/src/db/models/favorite/index.ts +++ b/src/db/models/favorite/index.ts @@ -5,7 +5,12 @@ import {AppError} from '@gravity-ui/nodekit'; import * as MT from '../../../types/models'; import {DlsActions} from '../../../types/models'; import Utils from '../../../utils'; -import {validateGetFavorites, validateAddFavorite, validateDeleteFavorite} from './scheme'; +import { + validateGetFavorites, + validateAddFavorite, + validateDeleteFavorite, + validateRenameFavorite, +} from './scheme'; import {RETURN_FAVORITES_COLUMNS} from '../../../const'; import {registry} from '../../../registry'; @@ -362,6 +367,35 @@ class Favorite extends Model { return result; } + + static async rename({ + tenantId, + entryId, + name, + requestedBy, + ctx, + dlContext, + }: MT.RenameFavoriteConfig) { + ctx.log('RENAME_FAVORITE_REQUEST', { + tenantId, + entryId, + name, + requestedBy, + dlContext, + }); + + validateRenameFavorite({entryId, name}); + + const result = await Favorite.query(this.primary) + .where({entryId}) + .update({alias: name}) + .returning('*') + .timeout(Model.DEFAULT_QUERY_TIMEOUT); + + ctx.log('RENAME_FAVORITE_SUCCESS'); + + return result; + } } export default Favorite; diff --git a/src/db/models/favorite/scheme.ts b/src/db/models/favorite/scheme.ts index 5a6b505f..34ff3fef 100644 --- a/src/db/models/favorite/scheme.ts +++ b/src/db/models/favorite/scheme.ts @@ -1,4 +1,4 @@ -import compileSchema from '../../../components/validation-schema-compiler'; +import compileSchema, {makeSchemaValidator} from '../../../components/validation-schema-compiler'; import {AJV_PATTERN_KEYS_NOT_OBJECT} from '../../../const'; export const validateGetFavorites = compileSchema({ @@ -76,3 +76,16 @@ export const validateDeleteFavorite = compileSchema({ }, }, }); +export const validateRenameFavorite = makeSchemaValidator({ + type: 'object', + required: ['entryId', 'name'], + properties: { + entryId: { + type: 'string', + }, + name: { + type: ['string', 'null'], + verifyEntryName: true, + }, + }, +}); diff --git a/src/routes.ts b/src/routes.ts index f8a16b2c..2ec5e3d9 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -253,6 +253,11 @@ export function getRoutes(nodekit: NodeKit, options: GetRoutesOptions) { handler: favoritesController.deleteFavorite, write: true, }), + renameFavorite: makeRoute({ + route: 'POST /v1/favorites/:entryId/rename', + handler: favoritesController.renameFavorite, + write: true, + }), }; if (isEnabledFeature(ctx, Feature.CollectionsEnabled)) { diff --git a/src/services/favorite.service.ts b/src/services/favorite.service.ts index e8c8dadd..3f10eec7 100644 --- a/src/services/favorite.service.ts +++ b/src/services/favorite.service.ts @@ -55,4 +55,18 @@ export default class FavoriteService { ctx, }); } + + static async rename({entryId, name, ctx}: ST.RenameFavorite) { + const {requestId, tenantId, user, dlContext} = ctx.get('info'); + + return await Favorite.rename({ + requestId, + tenantId, + entryId, + name, + requestedBy: user, + dlContext, + ctx, + }); + } } diff --git a/src/types/models/favorite.ts b/src/types/models/favorite.ts index 52867f5f..ec12f8dc 100644 --- a/src/types/models/favorite.ts +++ b/src/types/models/favorite.ts @@ -24,3 +24,9 @@ export interface DeleteFavoriteConfig extends BasicRequestParams { entryId?: any; ctx: CTX; } +export interface RenameFavoriteConfig extends BasicRequestParams { + entryId: string; + name: string; + ctx: CTX; + dlContext?: string; +} diff --git a/src/types/models/tables-columns.ts b/src/types/models/tables-columns.ts index 8f003943..1dc57e9e 100644 --- a/src/types/models/tables-columns.ts +++ b/src/types/models/tables-columns.ts @@ -87,5 +87,6 @@ export interface FavoriteColumns { entryId: string; tenantId: string; login: string; + alias: string | null; createdAt: string; } diff --git a/src/types/services.types.ts b/src/types/services.types.ts index a56be0f9..5d02ca57 100644 --- a/src/types/services.types.ts +++ b/src/types/services.types.ts @@ -98,6 +98,10 @@ export interface GetFavorite extends StdServiceParams { export interface AddFavorite extends StdServiceParams { entryId: string; } +export interface RenameFavorite extends StdServiceParams { + entryId: string; + name: string; +} export interface DeleteFavorite extends StdServiceParams { entryId: string; } From 29aed1d69649b259438c569941b381043640b3f3 Mon Sep 17 00:00:00 2001 From: Stanislav Kiselev <“staskis@yandex-team.ru”> Date: Wed, 6 Dec 2023 23:36:46 +0300 Subject: [PATCH 5/5] Extended new Favorite model with alias column --- src/db/models/new/favorite/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/db/models/new/favorite/index.ts b/src/db/models/new/favorite/index.ts index 6437c9df..0ca27fa2 100644 --- a/src/db/models/new/favorite/index.ts +++ b/src/db/models/new/favorite/index.ts @@ -26,6 +26,7 @@ export class Favorite extends Model { entryId!: string; tenantId!: string; login!: string; + alias!: string | null; createdAt!: string; entry?: Entry;