-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stage' into production
- Loading branch information
Showing
60 changed files
with
2,521 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
name: Documentation Request | ||
about: Request new, updates, or changes to documentation | ||
title: '[DOCS]' | ||
labels: 'Documentation' | ||
assignees: '' | ||
--- | ||
|
||
**Topic of request** | ||
What **topic** does this documentation request concern? | ||
<br> | ||
|
||
**Kind of request** | ||
Is this a request for **new documentation**? An **update**? Or a **change** to existing docs? | ||
<br> | ||
|
||
If this is a request to create **new** documentation, what do you think is important to include? | ||
<br> | ||
|
||
If this is a request to **update** existing documention, what needs to be updated? | ||
<br> | ||
|
||
If this is a request to **change** existing documentation, what needs to be changed? | ||
<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,67 @@ | ||
import { Request, Response } from 'express' | ||
import * as TE from 'fp-ts/TaskEither' | ||
import * as T from 'fp-ts/Task' | ||
import * as O from 'fp-ts/Option' | ||
import * as I from 'fp-ts/Identity' | ||
import { pipe } from 'fp-ts/function' | ||
import { AddSentenceCommandHandler } from '../../../application/sentences/use-case/command-handler/add-sentence-command-handler' | ||
import { AddSentenceCommand } from '../../../application/sentences/use-case/command-handler/command/add-sentence-command' | ||
import { | ||
SentencesRepositoryErrorKind, | ||
SentenceRepositoryErrorKind, | ||
SentenceValidationErrorKind, | ||
} from '../../../application/types/error' | ||
import { createPresentableError } from '../../../application/helper/error-helper' | ||
import { StatusCodes } from 'http-status-codes' | ||
import { validateSentence } from '../../../core/sentences' | ||
import { | ||
findDomainIdByNameInDb, | ||
saveSentenceInDb, | ||
} from '../../../application/sentences/repository/sentences-repository' | ||
import { findVariantByTagInDb } from '../../../application/sentences/repository/variant-repository' | ||
import { findLocaleByNameInDb } from '../../../application/sentences/repository/locale-repository' | ||
|
||
export default async (req: Request, res: Response) => { | ||
const { sentence, localeId, localeName, source, domains } = req.body | ||
const { sentence, localeName, source, domains, variant } = req.body | ||
|
||
const command: AddSentenceCommand = { | ||
clientId: req.client_id, | ||
sentence: sentence, | ||
localeId: localeId, | ||
localeName: localeName, | ||
source: source, | ||
domains: domains | ||
domains: domains, | ||
variant: O.fromNullable(variant), | ||
} | ||
|
||
return pipe( | ||
AddSentenceCommandHandler(command), | ||
const cmdHandler = pipe( | ||
AddSentenceCommandHandler, | ||
I.ap(validateSentence), | ||
I.ap(findDomainIdByNameInDb), | ||
I.ap(findVariantByTagInDb), | ||
I.ap(findLocaleByNameInDb), | ||
I.ap(saveSentenceInDb) | ||
) | ||
|
||
const result = await pipe( | ||
command, | ||
cmdHandler, | ||
TE.mapLeft(createPresentableError), | ||
TE.match( | ||
err => { | ||
switch (err.kind) { | ||
case SentencesRepositoryErrorKind: { | ||
return T.of(res.status(StatusCodes.INTERNAL_SERVER_ERROR).json(err)) | ||
case SentenceRepositoryErrorKind: { | ||
res.status(StatusCodes.INTERNAL_SERVER_ERROR) | ||
break | ||
} | ||
case SentenceValidationErrorKind: { | ||
res.status(StatusCodes.BAD_REQUEST) | ||
break | ||
} | ||
case SentenceValidationErrorKind: | ||
return T.of(res.status(StatusCodes.BAD_REQUEST).json(err)) | ||
} | ||
|
||
return err | ||
}, | ||
() => | ||
T.of( | ||
res.json({ | ||
message: 'Sentence added successfully', | ||
}) | ||
) | ||
() => ({ message: 'Sentence added successfully' }) | ||
) | ||
)() | ||
|
||
return res.json(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
server/src/application/sentences/repository/locale-repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { option as O, taskEither as TE } from 'fp-ts' | ||
import { ApplicationError } from '../../types/error' | ||
import { queryDb } from '../../../infrastructure/db/mysql' | ||
import { pipe } from 'fp-ts/lib/function' | ||
import { createDatabaseError } from '../../helper/error-helper' | ||
import { Locale, TextDirection } from '../../../core/types/locale' | ||
|
||
export type FindLocaleByName = ( | ||
localeName: string | ||
) => TE.TaskEither<ApplicationError, O.Option<Locale>> | ||
|
||
type LocaleRow = { | ||
id: number | ||
name: string | ||
targetSentenceCount: number | ||
isContributable: number | ||
isTranslated: number | ||
textDirection: TextDirection | ||
} | ||
|
||
export const findLocaleByNameInDb: FindLocaleByName = (localeName: string) => | ||
pipe( | ||
[localeName], | ||
queryDb( | ||
` SELECT | ||
id, | ||
name, | ||
target_sentence_count as targetSentenceCount, | ||
is_contributable as isContributable, | ||
is_translated as isTranslated, | ||
text_direction as textDirection | ||
FROM locales | ||
WHERE name = ? | ||
` | ||
), | ||
TE.mapLeft((err: Error) => | ||
createDatabaseError( | ||
`Error retrieving locale by name "${localeName}"`, | ||
err | ||
) | ||
), | ||
TE.map(([[result]]: Array<Array<LocaleRow>>) => { | ||
return pipe( | ||
result, | ||
O.fromNullable, | ||
O.map(result => ({ | ||
...result, | ||
isContributable: result.isContributable === 1, | ||
isTranslated: result.isTranslated === 1, | ||
})) | ||
) | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.