superdesk/superdesk-client-core

View on GitHub
scripts/extensions/sams/src/api/assets.ts

Summary

Maintainability
F
1 wk
Test Coverage

File assets.ts has 559 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// Types
import {
    IAttachment,
    IElasticRangeQueryParams,
    IRestApiResponse,
Severity: Major
Found in scripts/extensions/sams/src/api/assets.ts - About 1 day to fix

    Function queryAssets has 49 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function queryAssets(
        params: IAssetSearchParams,
        listStyle: ASSET_LIST_STYLE,
    ): Promise<IRestApiResponse<IAssetItem>> {
        const {gettext} = superdeskApi.localization;
    Severity: Minor
    Found in scripts/extensions/sams/src/api/assets.ts - About 1 hr to fix

      Function queryMimetypes has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function queryMimetypes(source: IRootElasticQuery, params: IAssetSearchParams) {
          if (params.mimetypes === ASSET_TYPE_FILTER.DOCUMENTS) {
              source.query.bool.must_not.push(
                  superdeskApi.elasticsearch.queryString({
                      query: 'mimetype:(image\\/*) OR mimetype:(video\\/*) OR mimetype:(audio\\/*)',
      Severity: Minor
      Found in scripts/extensions/sams/src/api/assets.ts - About 1 hr to fix

        Function getAssetsByIds has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function getAssetsByIds(ids: Array<string>): Promise<IRestApiResponse<IAssetItem>> {
            const {gettext} = superdeskApi.localization;
            const {notify} = superdeskApi.ui;
        
            return superdeskApi.dataApi.queryRawJson<IRestApiResponse<IAssetItem>>(
        Severity: Minor
        Found in scripts/extensions/sams/src/api/assets.ts - About 1 hr to fix

          Function queryMimetypes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          function queryMimetypes(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.mimetypes === ASSET_TYPE_FILTER.DOCUMENTS) {
                  source.query.bool.must_not.push(
                      superdeskApi.elasticsearch.queryString({
                          query: 'mimetype:(image\\/*) OR mimetype:(video\\/*) OR mimetype:(audio\\/*)',
          Severity: Minor
          Found in scripts/extensions/sams/src/api/assets.ts - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function queryDateRange has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          function queryDateRange(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.dateFrom != null || params.dateTo != null) {
                  const args: IElasticRangeQueryParams = {field: '_updated'};
          
                  if (params.dateFrom != null) {
          Severity: Minor
          Found in scripts/extensions/sams/src/api/assets.ts - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          export function unlockAsset(original: IAssetItem, updates: Dictionary<string, any>): Promise<Partial<IAssetItem>> {
              const {gettext} = superdeskApi.localization;
              const {notify} = superdeskApi.ui;
          
              return superdeskApi.dataApi.patch<IAssetItem>(UNLOCK_ASSET, original, updates)
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 1 other location - About 1 day to fix
          scripts/extensions/sams/src/api/assets.ts on lines 592..609

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 202.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          export function lockAsset(original: IAssetItem, updates: Dictionary<string, any>): Promise<Partial<IAssetItem>> {
              const {gettext} = superdeskApi.localization;
              const {notify} = superdeskApi.ui;
          
              return superdeskApi.dataApi.patch<IAssetItem>(LOCK_ASSET, original, updates)
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 1 other location - About 1 day to fix
          scripts/extensions/sams/src/api/assets.ts on lines 611..628

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 202.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

          function queryDescription(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.description != null && params.description.length > 0) {
                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.queryString({
                          query: `description:(${params.description})`,
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 2 other locations - About 4 hrs to fix
          scripts/extensions/sams/src/api/assets.ts on lines 153..163
          scripts/extensions/sams/src/api/assets.ts on lines 165..175

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 117.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

          function queryName(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.name != null && params.name.length > 0) {
                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.queryString({
                          query: `name:(${params.name})`,
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 2 other locations - About 4 hrs to fix
          scripts/extensions/sams/src/api/assets.ts on lines 165..175
          scripts/extensions/sams/src/api/assets.ts on lines 177..187

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 117.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

          function queryFilename(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.filename != null && params.filename.length > 0) {
                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.queryString({
                          query: `filename:(${params.filename})`,
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 2 other locations - About 4 hrs to fix
          scripts/extensions/sams/src/api/assets.ts on lines 153..163
          scripts/extensions/sams/src/api/assets.ts on lines 177..187

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 117.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

          function querySetIds(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.setIds != null && params.setIds.length > 0) {
                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.terms({
                          field: 'set_id',
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 4 other locations - About 3 hrs to fix
          scripts/extensions/sams/src/api/assets.ts on lines 83..92
          scripts/extensions/sams/src/api/assets.ts on lines 120..129
          scripts/extensions/sams/src/api/assets.ts on lines 131..140
          scripts/extensions/sams/src/api/assets.ts on lines 142..151

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 103.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

          function queryExcludedAssetIds(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.excludedAssetIds != null && params.excludedAssetIds.length > 0) {
                  source.query.bool.must_not.push(
                      superdeskApi.elasticsearch.terms({
                          field: '_id',
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 4 other locations - About 3 hrs to fix
          scripts/extensions/sams/src/api/assets.ts on lines 83..92
          scripts/extensions/sams/src/api/assets.ts on lines 94..103
          scripts/extensions/sams/src/api/assets.ts on lines 131..140
          scripts/extensions/sams/src/api/assets.ts on lines 142..151

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 103.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

          function querySetId(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.setId != null && params.setId.length > 0) {
                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.term({
                          field: 'set_id',
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 4 other locations - About 3 hrs to fix
          scripts/extensions/sams/src/api/assets.ts on lines 94..103
          scripts/extensions/sams/src/api/assets.ts on lines 120..129
          scripts/extensions/sams/src/api/assets.ts on lines 131..140
          scripts/extensions/sams/src/api/assets.ts on lines 142..151

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 103.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

          function queryState(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.state != null && params.state.length > 0) {
                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.term({
                          field: 'state',
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 4 other locations - About 3 hrs to fix
          scripts/extensions/sams/src/api/assets.ts on lines 83..92
          scripts/extensions/sams/src/api/assets.ts on lines 94..103
          scripts/extensions/sams/src/api/assets.ts on lines 120..129
          scripts/extensions/sams/src/api/assets.ts on lines 142..151

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 103.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

          function queryStates(source: IRootElasticQuery, params: IAssetSearchParams) {
              if (params.states != null && params.states.length > 0) {
                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.terms({
                          field: 'state',
          Severity: Major
          Found in scripts/extensions/sams/src/api/assets.ts and 4 other locations - About 3 hrs to fix
          scripts/extensions/sams/src/api/assets.ts on lines 83..92
          scripts/extensions/sams/src/api/assets.ts on lines 94..103
          scripts/extensions/sams/src/api/assets.ts on lines 120..129
          scripts/extensions/sams/src/api/assets.ts on lines 131..140

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 103.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.terms({
                          field: 'tags.code',
                          value: taglist,
                      }),
          Severity: Minor
          Found in scripts/extensions/sams/src/api/assets.ts and 1 other location - About 35 mins to fix
          scripts/extensions/sams/src/api/assets.ts on lines 111..116

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 46.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  source.query.bool.must.push(
                      superdeskApi.elasticsearch.terms({
                          field: 'set_id',
                          value: setIds,
                      }),
          Severity: Minor
          Found in scripts/extensions/sams/src/api/assets.ts and 1 other location - About 35 mins to fix
          scripts/extensions/sams/src/api/assets.ts on lines 196..201

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 46.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status