Skip to content

Commit

Permalink
- fixed server.syncVersions to accept empty body
Browse files Browse the repository at this point in the history
- fixed core.addBookWithContent to update all book metadata
  • Loading branch information
chriswep committed Oct 9, 2020
1 parent 317ea9e commit 8530a54
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/src/Bible.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
params: {
lang: FirstArgument<BibleController['syncVersions']>;
},
data: SecondArgument<BibleController['syncVersions']>,
data?: SecondArgument<BibleController['syncVersions']>,
) {
let path = '/bible/versions/:lang';

Expand Down
4 changes: 2 additions & 2 deletions core/src/BibleEngine.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class BibleEngine {
} else {
bookEntity = await this.updateBook(
bookEntity,
{ dataLocation: 'importing' },
{ ...bookInput.book, dataLocation: 'importing' },
options.entityManager
);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ export class BibleEngine {
} else {
bookEntity = await this.updateBook(
bookEntity,
{ dataLocation: 'importing' },
{ ...bookInput.book, dataLocation: 'importing' },
transactionEntityManger
);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/entities/BibleVersion.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class BibleVersionEntity implements IBibleVersion {
lastUpdate: Date;

@Column({ type: 'varchar' })
dataLocation?: 'db' | 'file' | 'remote';
dataLocation?: IBibleVersion['dataLocation'];

constructor(initializer: IBibleVersion) {
Object.assign(this, initializer);
Expand Down
8 changes: 5 additions & 3 deletions importers/src/BeImportFileCreator.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class BeImportFileCreator {
language: versionEntity.language,
chapterVerseSeparator: versionEntity.chapterVerseSeparator,
hasStrongs: versionEntity.hasStrongs,
type: versionEntity.type,
lastUpdate: versionEntity.lastUpdate
},
file: await this.createVersionFile(versionEntity.uid, options)
Expand Down Expand Up @@ -89,7 +90,8 @@ export class BeImportFileCreator {
async createVersionFile(versionUid: string, options?: BeFileCreatorOptions) {
const versionData = await this.bibleEngine.getVersionFullData(versionUid);
const targetDir = this.destinationPath + '/' + versionData.version.uid;
const targetFile = `${this.destinationPath}/${versionData.version.uid}.bef`;
const targetFile = `${versionData.version.uid}.bef`;
const targetPath = `${this.destinationPath}/${targetFile}`;

const p = new Promise<string>((pResolve, pReject) => {
// create version directory
Expand Down Expand Up @@ -135,10 +137,10 @@ export class BeImportFileCreator {
}
});

const output = createWriteStream(targetFile);
const output = createWriteStream(targetPath);
output.on('close', function() {
const bytes = zipArchive.pointer();
console.log(`${targetFile} was successfully created with ${bytes} total bytes`);
console.log(`${targetPath} was successfully created with ${bytes} total bytes`);
rmDirRecSync(targetDir);
pResolve(targetFile);
});
Expand Down
12 changes: 6 additions & 6 deletions server/src/Bible.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export class BibleController {
@Post('/versions/:lang')
async syncVersions(
@Param('lang') lang: string,
@Body({ required: true })
clientVersions: {
@Body()
clientVersions?: {
[index: string]: {
lastUpdate: string | Date;
dataLocation: Required<IBibleVersion>['dataLocation'];
Expand All @@ -123,24 +123,24 @@ export class BibleController {

for (const version of langVersions) {
if (
!clientVersions[version.uid] ||
!clientVersions?.[version.uid] ||
(clientVersions[version.uid].dataLocation === 'remote' &&
new Date(clientVersions[version.uid].lastUpdate) < version.lastUpdate)
) {
const versionBooks = await this.bibleEngine.getBooksForVersion(version.id);
remoteUpdates.push({
uid: version.uid,
meta: stripUnnecessaryDataFromBibleVersion(version),
change: !clientVersions[version.uid] ? 'new' : 'updated',
change: !clientVersions?.[version.uid] ? 'new' : 'updated',
books: versionBooks.map((book) => stripUnnecessaryDataFromBibleBook(book)),
});
}
}

// check if a version has been deleted on the server
for (const clientVersionUid of Object.keys(clientVersions)) {
for (const clientVersionUid of Object.keys(clientVersions || {})) {
if (
clientVersions[clientVersionUid].dataLocation === 'remote' &&
clientVersions?.[clientVersionUid].dataLocation === 'remote' &&
!langVersions.find((version) => version.uid === clientVersionUid)
)
remoteUpdates.push({ uid: clientVersionUid, change: 'deleted' });
Expand Down

0 comments on commit 8530a54

Please sign in to comment.